That's all you can do. A service process is 3rd on the "importance
hierarchy" in the system deciding which processes should not be
killed. Just behind a 'visible process' such as a paused activity.

"3. A service process is one holding a Service that has been started
with the startService() method."
http://code.google.com/android/intro/lifecycle.html


"The solution to this problem is to start a Service from the
BroadcastReceiver, so the system knows that there is still active work
being done in the process."
http://code.google.com/android/intro/lifecycle.html

- Juan T.

On Dec 17, 8:21 pm, polo777 <[email protected]> wrote:
> Ok thanks for your answer. I am going to investigate in this way.
> However, according to my understanding, even though the service will
> have a longer life time than the thread, it still can be killed. Then,
> for a real safe mechanism I guess I have to take care of the problem
> differently meaning perhaps changing  the nature of my code.
>
> On Dec 17, 4:06 pm, Al <[email protected]> wrote:
>
> > 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 
> > athttp://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 <[email protected]> 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 theactivityor 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 [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
-~----------~----~----~----~------~----~------~--~---

Reply via email to