The best thing is to stick with onDestroy, because you don't know when the phone will actually garbage collect your Activity object.
Of course, traditionally, you would override finalize() in your object. I haven't played with this on Android yet. However, you should be careful to note the API documentation on that method: "Note that the VM does guarantee that finalize() is called at most once for any object, but it doesn't guarantee when (if at all) finalize () will be called. For example, object B's finalize() can delay the execution of object A's finalize() method and therefore it can delay the reclamation of A's memory. To be safe, use a ReferenceQueue, because it provides more control over the way the VM deals with references during garbage collection. " So, check out ReferenceQueue. Again, I haven't played around with it, but it might give you what you want. Richard Schilling Root Wireless On Jul 22, 12:30 pm, "Mapara,Harshit Nitinkumar" <[email protected]> wrote: > Hi all, > > I have requirement that needs to save data to a file. During multiple > Activitiy screens, I add different data to a list > and finally when user is not using the app (means if user exits app by > pressing "home" button or "call" button), just before exiting that > app, i want to save that data of the list to a file. > > coding before exiting activity screen is simple - by calling onDestory > () method, but here I want not one activity but the application exit. > > So my question is How do I write a code that will be executed just > before application exits ? > I tried created one class extends Application, and then I override > onTerminate() method, but it's not get called when I exit ( pressing > home button on device) > > Plz help > Thanks > Harshit --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

