This will work if you just want to get rid of the null pointer exceptions.

However, you just should never do any background work in an activity, i.e. 
run code in an Activity on the stack of a background thread (in your case, 
calling Activity.doBackgroundRequest()). It will set you up for problems.

It is unlikely, but not impossible, that the UI thread kicks in after a 
phone rotation, between the assignment of checkedActivity and the execution 
of checkedActivity.doBackgroundRequest(), and calls the onDestroy of the 
activity. How would that behave for your app?

The proper way of doing this is to execute code in the background that does 
*not* require an activity (or any UI type of object) to be accessed. If 
this background processing yields a result that needs to be communicated to 
the screen (Activity/View/etc), then you'll implement onPostExecute to do 
so.

*Refactor *your code do move the code in 'doBackgroundRequest' out of your 
activity and put it into your subclass of AsyncTask instead. If you need 
pieces of data from your activity, assign just those pieces to the new 
QuadrosMobileActivityTask object when you construct it.

If you access your activity in the construction of the AsyncTask and in the 
onPreExecute and onPostExecute only, you no longer need to use 
'synchronized' blocks anymore... all access is done on one thread (the main 
UI thread) only. 




-- 
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

Reply via email to