Thank you, Mark.

I read your linked topic, But AlarmManager is not suitable to me.

My service is not started periodically, it started by broadcast,
Actually by "android.intent.action.PHONE_STATE".

On each starting, the service should load a big database, this spend
about serveral seconds, so I don't want to load it each time
"android.intent.action.PHONE_STATE" arrive, I leave the service
runing.

For each "android.intent.action.PHONE_STATE", a UI should be present
to user while calling, in order to show the UI in front of calling and
not to interrupt the interaction with phone call, the UI should not be
a activity, I user "WindowManager.LayoutParams.TYPE_SYSTEM_ALERT" with
FLAG__NOT_FOCUSABLE.

In above condition, except to Service, there is any better class I can
use? pls advise me.

If I have to user Service, Where should I do cleaning up and saving
settings?

Thank you!

On Dec 10, 7:33 pm, "Mark Murphy" <mmur...@commonsware.com> wrote:
> > I have a Service, it is started by StartService(...), my program never
> > stop it. The service can be destroied in other cases, such as:
> >   Stop it in Application->Running Services
> >   run command: Kill <pid>
> >   System kill it in case of memory low
> >   Phone shut down
> >   other unlist condition...
>
> > I want to clean up and save settings whenever the service is
> > destroied. I tried do this in onDestroy() or finalize(), Neither
> > satisfies my demand, onDestroy() is only called whe "Stop it in
> > Application->Running Services", finalize() is never called in all
> > above condition.
>
> > Where is the right point? pls help me, THANK YOU!
>
> There is no "right point" for those scenarios. Your code will not be
> called. Hence, do not wait to be destroyed to "clean up and save
> settings".
>
> And, please do not leave your service running all of the time:
>
> http://www.androidguys.com/2009/09/09/diamonds-are-forever-services-a...
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com
> Android App Developer Books:http://commonsware.com/books.html

-- 
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

Reply via email to