[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-11-20 Thread BelvCompSvs
doInBackground like you have it is not the way to do that -- what you have coded is called spinning Kostya Vasilyev's explanation is clearer than mine and will move you in the direction of correct code if you take the suggestion and continue to work it but rather than doing a spin-lock as a wait

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-11-18 Thread BelvCompSvs
better not to null it unless absolutely sure at a level of work V. is trying to get you to do best is to use onPreExecute and onPostExecute as shown by Skyler a while back and as well since this is Mult-Thread and that is dicey without correct code then one approach is to syncronize( ObjectRef )

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-27 Thread Bluemercury
What about extending the async task and then implement the logic directly in the doInbackground method? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe

Re: [android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-27 Thread Kostya Vasilyev
Yes, that's the more usual pattern. You'll still likely need an activity reference to show progress and display results, but there are special methods in AsyncTask for that, which are automatically called on the UI thread - thus, you'll be avoiding multiple threads trying to access and modify

Re: [android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-27 Thread Bluemercury
Yes i have a indeterminate progressBar in the header, the spinner one, but im using broadcast to all the activities which have the spinner to show or hide it if there's a task running in the background : @Override protected void onPreExecute() {

Re: [android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-27 Thread Kostya Vasilyev
You still have access to a member variable (activity) inside code that runs on the non-UI (worker) thread. Either: - Do not reference the activity from doInBackground, moving the actual code here from activity.doBackgroundRequest - Or learn the basics the thread synchronization, so that your UI

Re: [android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-27 Thread Bluemercury
Hi there! Yes i removed the code from activity.doBackgroundRequest to the extending Async Tasks doInBackground, i think it might solve this, BUT i will se the thread synchronization topic. Thanks for the attention. -- You received this message because you are subscribed to the Google Groups

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
No one? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options,

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Streets Of Boston
You cannot just use a reference(be it explicit or implicit to an inner class definition) to an Activity in the doInBackground of an AsyncTask (or in any method that is executed on a background thread). You'll get the problem you see right now. First, i would suggest trying not to use an

Re: [android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Mark Murphy
On Wed, Oct 26, 2011 at 9:22 AM, Streets Of Boston flyingdutc...@gmail.com wrote: First, i would suggest trying not to use an Activity reference in your doInBackground at all. Maybe you can just use a Context (activity.getApplicationContext()) instead. Or, get the data you need out of the

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
Well the thing is, this Asynctask is binded to a parent activity, that the subactivities use when they want to do some background work. They each implement the method you see in the code i've posted, the * activity.doBackGroundRequest(); * I've actually had errors even after the line

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
Also wouldnt using the activity.getApplicationContext() result in the same problem??? if activity is null i would stil lget the null exception??? regards, -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Skyler
activity#getApplicationContext returns the Application context, which is a reference to this class, http://developer.android.com/reference/android/app/Application.html, and is available for the livetime of your application. On Oct 26, 11:40 am, Bluemercury joao.ro...@gmail.com wrote: Also

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
yes, but how can i get the method from the activity that contains the logic to do in the background from the context, is this possible? im getting null exception for the activity after verifying if the activity is not null: if(activity!=null){ return

Re: [android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Kostya Vasilyev
This happens during orientation changes, correct? What you have is two threads accessing and modifying the same variable at the same time. Take some time to learn about multithreaded programming in Java: concurrent access and modification of a variable is one of the things that fall under

Re: [android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Mark Murphy
On Wed, Oct 26, 2011 at 11:31 AM, Bluemercury joao.ro...@gmail.com wrote: Well the thing is, this Asynctask is binded to a parent activity, that the subactivities use when they want  to do some background work. They each implement the method you see in the code i've posted, the 

Re: [android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
How so? each activity launches its own async task with its own specific logicwhen you rotate you just detach the current activity from the async task, the activity gets destroyed, a new one is created and attached to the SAME async task -- You received this message because you are

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Skyler
I'm surprised Mark hasn't posted this yet. This may be of help to you, AsyncTask and Screen Rotation http://commonsware.com/blog/2010/09/10/asynctask-screen-rotation.html. On Oct 26, 1:18 pm, Bluemercury joao.ro...@gmail.com wrote: How so? each activity launches its own async task with its own

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
Hey Skyler, thanks for the link. so i need to get rid of activity reference on the doInBackground...i assume its possible to use the activity reference in the preExecute and post -- You received this message because you are subscribed to the Google Groups Android Developers group. To post

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Skyler
Yes, you can safely use activity references in onPreExecute and onPostExecute, because those are run on your application's main thread, the same thread that all framework components run on. So by referencing your activity in onPreExecute and onPostExecute you wont need to contend with with any

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
Hi again skyler, thanks for the reply, yes the code im using in the doInBackground deals with the logic i want to do in the background that each activity has, in this case the method doBackgroundRequest is the method every activity uses if it wants to use an async task...but it seems this