Prevent service being destroyed.

Put your problem here if it does not fit any of the other categories.

Prevent service being destroyed.

Postby prc » Thu Nov 13, 2008 8:26 am


I'm developing a software that has kind of 3 parts.

A broadcastlistener that will react when phone has completed booting.
A service that handles my database stuff and searches into the db.
A gui componen for user to use the software.

My problem is that when GUI is shutdown (and service is unbound) the service is destroyed also. I was wondering how I could make the service to run as a Daemon so that would not get destroyed ever.

So to be clear. At first the service is running, even tho the GUI is not. When the GUI connects (bind) to the service (localservice) it works. After I shutdown the GUI, my service will run to method onDestroy().

I need to keep the service alive, because it is supposed to react to incoming calls and act on them. Starting the service on incoming call might be too slow.

By broadcast listener starts the service as follows:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  2.             Intent launcher = new Intent( context, SillyService.class );
  4.             launcher.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK  );
  6.             context.startService( launcher );
Parsed in 0.010 seconds, using GeSHi

Api doc says that the service should stay running until stopService() is called. But when my GUI disconnects it still gets nuked.

from apidoc:

"Using startService() overrides the default service lifetime that is managed by bindService(Intent, ServiceConnection, int): it requires the service to remain running until stopService(Intent) is called, regardless of whether any clients are connected to it. "

** edit **

nwm. I found out why this happened. Service had crashed during testing, and my GUI started it again by binding, so of course it died on unbind. Rebootting fixed this as my listner started service after boot with startService(..);

Posts: 4
Joined: Thu Nov 13, 2008 8:11 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 6 guests