You don't "exit" an application; in fact an application is a fairly nebulous concept on Android. You should do this kind of stuff in Activity -- for example, as long as you have an activity in the start state, then continue running your work thread.
On Wed, Nov 18, 2009 at 2:02 AM, Syl <[email protected]> wrote: > I would like to know how to execute code before exiting application. > > My application is composed of several activities. When the user starts > the application (from the launcher menu or from a notification in the > status bar), he goes in an InitActivity where I process some > initializations. From user experience, application always restarts. > > One of these initializations is to init a network manager and start a > thread that periodically sends a network request to notify a server > that application is active. > > I need to process some end operations, like stopping this thread when > user quits application, for example by pressing the HOME key or BACK > key when he's in the root activity. > > However, when the user press the HOME key, application is still > running in background. > > > Here are my questions : > > Q1 : is it possible to execute code when exiting application (I see > the onTerminate() method of the class Application but it seems not to > be always called) ? > > Q2 : Is it possible to force application exit (activity method finish > () only destroy the current activity, not the application) ? > > Q3 : Is it possible to handle HOME key press (onKeyDown() is not > called when this button is pushed) ? > > Thanks for your help. > > -- > 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 > -- 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

