sdphil wrote:
> based on some other posts I have seen, I created a static variable
> inside my service class and I initialize it to false. when the
> service is created, I set it to true.
>
> public class MyService extends Service {
> private static boolean running = false;
> ...
> ...
> @Override
> public void onCreate() {
> super.onCreate();
>
> running = true;
> ...
> ...
>
> then when I come back up, I can just check if Service.running is true
> - if it is, then my service object is still alive.
You are mistaken. It means the process was not closed down. In Java,
static data members live outside of any one instance of the class they
are a part of.
> to answer your question more specifically - I do have a background
> thread, but the whole point was that I wanted this service to run even
> though the app was closed (i.e. no activities) (isn't that the point
> of a service) ?
It is one use of a service.
> "Otherwise, the service object, while detached from Android, will live
> until the thread terminates, or until Android force-closes your
> process due to lack of memory."
>
> which is exactly what I want...
Hopefully this is not what you want -- I really expect your users do not
want you leaking memory and threads like a sieve.
If your goal is to have the service to persist after all activities that
were using it have been destroyed, then you need to use startService(),
perhaps in addition to bindService().
"A service can be both started and have connections bound to it. In such
a case, the system will keep the service running as long as either it is
started or there are one or more connections to it with the
Context.BIND_AUTO_CREATE flag. Once neither of these situations hold,
the service's onDestroy() method is called and the service is
effectively terminated. All cleanup (stopping threads, unregistering
receivers) should be complete upon returning from onDestroy(). "
(from http://developer.android.com/reference/android/app/Service.html)
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy
Need Android talent? Ask on HADO! http://wiki.andmob.org/hado
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---