So im using an AsyncTask but i'm getting random null exceptions for the
activity reference in the doInBackground method. Anyway here's the non
inner public async task:
public class QuadrosMobileActivityTask extends AsyncTask<Void, Void,
Object>{
*protected QuadrosMobileActivity activity=null;*
protected QuadrosMobileApplicationContext mApp;
public QuadrosMobileActivityTask(*QuadrosMobileActivity activity*) {
attach(*activity*);
mApp=(QuadrosMobileApplicationContext)* activity.getApplication()*;
}
@Override
protected void onPreExecute() {
Logger.write("QuadrosMobileActivityTask ", " AsyncTask pre execution "+
"Current Activity: "+*activity.getClass().getName()*, Logger.INFO);
Intent broadcast = new Intent();
broadcast.setAction("SHOW_PROGRESSBAR");
mApp.sendBroadcast(broadcast);
mApp.setProgressBarInitialState(ProgressBar.VISIBLE);
}
@Override
protected Object doInBackground(Void... params) {
if(*activity!=null*){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Logger.write("QuadrosMobileActivityTask ", " AsyncTask background
initialized "+"Current Activity:
"+*activity.getClass().getName(),*Logger.INFO);
return *activity.doBackGroundRequest(); -->getting random null exceptions
for activity reference*
}else{
Logger.write("QuadrosMobileActivityTask ", "AsyncTask finished while no
Activity was attached.", Logger.INFO);
return null;}
}
@Override
protected void onPostExecute(Object result) {
if(*activity!=null*){
Logger.write("QuadrosMobileActivityTask ", " AsyncTask post execution
"+"Current Activity: "+*activity.getClass().getName()*, Logger.INFO);
//update results
*activity.updateResultsInUi(result);*
mApp.getAsyncTasks().remove(this);
//check if there's more tasks in the collection
if(mApp.getAsyncTasks().isEmpty()){
Intent broadcast = new Intent();
broadcast.setAction("HIDE_PROGRESSBAR");
mApp.sendBroadcast(broadcast);
mApp.setProgressBarInitialState(ProgressBar.GONE);
}
}
}
void detach() {
*activity=null;*
}
void attach(QuadrosMobileActivity *activity*) {
*this.activity=activity;*
}
}
Is there any reason this should even happen???does the sleep timer is
really necessary for waiting after the rotation is finished?
regards,
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en