Also you can check isFinishing() in onDestroy() to find out of the activity is actually being finished. This is described in the onDestroy() documentation: http://developer.android.com/reference/android/app/Activity.html#onDestroy()
<http://developer.android.com/reference/android/app/Activity.html#onDestroy()>For retaining active state across configuration changes, the "ideal" way is to onRetainNonConfigurationInstance(): http://developer.android.com/reference/android/app/Activity.html#onRetainNonConfigurationInstance() <http://developer.android.com/reference/android/app/Activity.html#onRetainNonConfigurationInstance()>Unfortunately I don't know if we have any good examples of using this to model after, but I am working on one that can serve the purpose for the next release. On Fri, Sep 18, 2009 at 11:00 PM, EboMike <[email protected]> wrote: > > That is a very bad way of doing it. What if the user presses the HOME > button? What if the user goes to a different activity using the > notification bar? The camera button? What if it's a device that allows > switching activities using a custom button? > > Relying on a button press to detect the lifetime of your application > is a major hack and bound to break in many ways. > > You might want to read the documentation for the Activity class to see > how the lifetime of an application works. It goes in detail about what > each stage does: onPause wants you to suspend your threads. onDestroy > means your app will be gone for good if isFinishing() is set. > > If you want to handle the specific case of an orientation change, you > can respond to onConfigurationChanged(). > > I would strongly advise against any kind of hacks circumventing those > methods. > What are you trying to do in your back button code? > > -Mike > > > On Sep 17, 2:28 pm, Nanard <[email protected]> wrote: > > I have founded ! Thanks > > > > I should not rely on onStop() nor onDestroy() to know when I quit my > > Activity. > > > > The only safe way is : > > > > @Override > > public boolean onKeyDown(int keyCode, KeyEvent event) { > > > > if (keyCode == KeyEvent.KEYCODE_BACK) { > > ... do some cleaning here > > } > > return super.onKeyDown(keyCode, event); > > } > > > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

