Tin
Tin

Reputation: 719

Android service killed unexpectedly

I have an Android service that's responsible for firing notifications at certain points in time. I use an android.OS.CountdownTimer for this. An activity creates and starts the service. If the phone is locked, notifications that are within let's say 1min are shown. Notifications that are much later are never shown. The service is unbound from the activity when the activity is onpause.

As long as the phone doesn't lock the notifications are generated, even if the activity is stopped and unbound from the service.

It seems to me that the service is stopped/killed. When I make the application debuggable and debug it on target, it works fine, also when the activity is stopped and the service is unbound.

The app is developed for v1.5 and runs at Galaxy S with 2.2.

Service is started as shown below

serviceIntent = new Intent().setAction("com.mytest.MyService");
startService(serviceIntent);
bindService(new Intent(context, 
         MyService.class), mConnection, 0 /*Context.BIND_AUTO_CREATE*/);

Upvotes: 1

Views: 1690

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006584

I have an Android service that's responsible for firing notifications at certain points in time. I use an android.OS.CountdownTimer for this.

Please do not do this. Please use AlarmManager and an IntentService, so you do not have a service running all of the time. Users will kill your service using a task killer or the Manage Services screen in the Settings app. Android will stop your service. You are better served going with an architecture (AlarmManager/IntentService) that works in accordance with user and platform wishes.

Upvotes: 1

Related Questions