Try calling startActivity first, then finish. Both are processed
asynchronously (afaik), after the calling method returns control to the
framework.

--
Kostya Vasilyev -- http://kmansoft.wordpress.com

08.09.2010 23:51 пользователь "OldSkoolMark" <[email protected]>
написал:

I've been using code like:

activity.finish();
activity.startActivity(new Intent(activity, activity.getClass()));

in two places: onResume(), and in an onClick() method of an
AlertDialog. I'm getting the desired results when the code is called
from onClick(), but I get mysterious null pointer exceptions while the
runtime is trying to execute my onPause(). Is calling finish() from
within one of the Activity lifecycle callbacks always a bad idea?

This code makes me nervous even though it works in the onClick().
After I call activity.finish(), I would think activity is in a
questionable state by the time activity.startActivity() is invoked.
Seems like an invitation to race conditions.

My use case is setting UI preferences (e.g. a different layout) in a
PreferenceActivity. When I return to the main activity's onResume(), I
check for preference changes and if a new layout is requested, I use
the code snippet above.

Alternative design approaches would also be greatly appreciated.

--
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]<android-developers%[email protected]>
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

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