I can't think of a problem with that. Do you see anything weird? -Kumar Bibek http://techdroid.kbeanie.com
On Sep 9, 12:44 am, OldSkoolMark <m...@sublimeslime.com> wrote: > 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 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