I'm guessing that your first background task was running the whole
time, and when you restarted your application you got a new instance
of the activity, and probably you created a new instance of the
background task so now you have two tasks running. The old activity is
not accessible to you anymore, and perhaps there's something else in
your background task that you're not showing, (in the part that
updates progress perhaps?) that is trying to access something that's
just not there.

If your application stays alive but the activity is re-created, you
need some way to re-establish a connection between your new activity
and your old background task. Firing up a second task is not what you
want to do. You could check out onRetainNonConfigurationChange() and
getLastNonConfigurationInstance() as one possible way to hang on to
the background task between activities, or you might want to keep a
pointer to the background task in your application context. Your code
in the background task that updates the activity needs to know when
the activity has gone away and when you get a new one.

Or you could put something in the background task to kill it off when
the activity goes away, like calling a method within the activity's
onDestroy() to tell your task class to wrap it up and stop.

- dave
www.androidbook.com

On Oct 23, 6:45 am, Mark Murphy <mmur...@commonsware.com> wrote:
> On Sat, Oct 23, 2010 at 4:57 AM, chcat <vlyamt...@gmail.com> wrote:
> > I have activity class running infinite loop in BackgroundAsyncTask
>
> The AsyncTask is designed for a "task", something that will run for a
> short while and end. If you want a long-running background thread, I
> recommend you fork your own thread.
>
> > I have a problem trying to "finish" this activity, when i press
> > "btnClose" the activity window disappears
>
> Please let the user exit the activity using the BACK button. There is
> no need to have a separate UI widget for this.
>
> > Any idea where is null pointer exception coming from and how to do it
> > right?
>
> Based on the code that you posted, your socket is null, because you
> never open one.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android 2.2 Programming Books:http://commonsware.com/books

-- 
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, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to