Regarding my new app KeepItOn, has being reported some bugs describe that app stops working. Testing on my devices all is working as expected, and after some research I found the problem was in the android version(4.4.2), as indicated here.

Returning START_STICKY on service, you are telling the system that you want to restart the service, when sufficient memory became available, after the service has been killed because of low memory. This behavior does not occur in the android 4.4.2.

The only workaround for that bug that I found is running the service in foreground instead of a background.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
   ...
   sendServiceForeground();

   return START_STICKY;
}
public void sendServiceForeground(){
   Notification notification = new Notification(R.drawable.ic_stat,
                "MyApp",System.currentTimeMillis());
   Intent notificationIntent = new Intent(this, MainActivity.class);
   PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
   notification.setLatestEventInfo(this, "MyApp",
                "description", pendingIntent);
   startForeground(ONGOING_NOTIFICATION_ID, notification);
}

This bug was fixed in Android 4.4.3 and earlier versions also does not seem to exhibit this problem.

Frederico Silva

Software Engineer

fredericojssilva fredericojss


Published