You could create a service for the background task. Create your main Activity, call startService(....), inside the service, create a thread, finish your work, then call stopSelf() to stop your service. Have a look at http://code.google.com/android/reference/android/app/Service.html. Services usually last longer and killed later then usual activities when memory is low.
On Dec 17, 11:47 pm, polo777 <polodr...@yahoo.com> wrote: > Hi Everyone, > > I am currently working on an app that uses two threads: The first main > UI one and a secondary one that I use to retrieve some data from the > network, parse them and finally add them into a database. > > My question is regarding to the lifecycle of my thread. The problem is > simple, I need the thread to end the work it is doing. > > The user can close the activity or send it to the background at > anytime which is not a problem for the main thread that take cares of > the UI but the secondary thread is still running and can be killed at > anytime stopping its work in a way that we don't control anything > (could be working on the database, parsing...). > > What is the best solution to handle this problem? > > Thanks a lot in advance. > Polo --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---