The problem is that the unkillable service is still killed by the system.
The essence of the service is a GPS tracker, which must constantly send data to the server.
On the emulator it works fine, on devices it constantly drops and does not resume. On my device (Lenovo S820) I tried to kill the process with scavengers and manually unload from the list of running applications. Both options lead to termination without subsequent recovery. When the phone is put into sleep mode, the result is the same.

What has been done for indestructibility:

put a restart of the service after it was closed:

public int onStartCommand(Intent intent, int flags, int startId) { ...... return START_STICKY; } 

added foreground notification:

 public void onCreate() { ....... this.makeForegroundNotification(); ....... } public void makeForegroundNotification() { if (mNotificationManager == null) { mNotificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); } Intent intent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(pendingIntent) .setTicker(getString(R.string.georequest_foreground_ticker)) .setContentTitle(getString(R.string.georequest_foreground_title)) .setContentText(getString(R.string.georequest_foreground_text)) .setSmallIcon(R.drawable.ic_gris_notif) .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_gris_logo)) .setPriority(NotificationCompat.PRIORITY_MAX); Notification notification = builder.build(); notification.flags |=Notification.FLAG_NO_CLEAR; startForeground(FOREGROUND_NOTIFICATION_ID, notification); } 

AlarmManager to the onCreate() service:

  AlarmManager manager = (AlarmManager)getSystemService(ALARM_SERVICE); Intent receiverIntent = new Intent(getApplicationContext(), CheckServiceReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 3, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT); manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 5000, (60*1000), pendingIntent); 

Also added a service to autorun.

On its device, when the service is unloaded, the AlarmManager also AlarmManager (for checking it registered Toast output on each trigger). The service does not crash in sleep mode if the activity of this application remains running.

    1 answer 1

    Poke in this direction:

     PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); wakeLock.acquire(); 

    http://developer.android.com/intl/ru/training/scheduling/wakelock.html

    I did the uninterrupted GPS survey service.

    • I tried, but no effect - Turkovsky
    • Then try all the code in try catch and analyze what is going on inside. Androyd is a delicate matter) - FreeDooM
    • Wrapped up. And catch error displays in the logs and saves in preference for more control. Nowhere is anything ( - Turkovsky