1. Everything Android is a community forum that makes it easy to ask questions about anything and everything Android. It's 100% free and no registration required (though we think it would be awesome if you joined our community). Our community of experts are here to help.
    Dismiss Notice

Background services stops working on closing app in marshmallow.Boot receive also not working

Discussion in 'Android Questions' started by Neha Mittal, Jul 14, 2017.

  1. Neha Mittal

    Neha Mittal Guest

    Sponsored Ad

    I am developing an app in which a background service for tracking location should run always (every half an hour sending location coordinates to server).My app is working fine with android 5 and android 7(in doze mode as well) but in android 6 the service stops working when i exit the app.Boot receive is also not working in android 6. Using alarmmanager on main thread for starting service.
    Below is the alarmmanager function i m using on my main thread.
    public void AlarmManagerFunc()
    {
    Context ctx = getBaseContext();
    AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
    long interval = 1000 * 60 * 15; //15 minutes in milliseconds
    long period = 1000;
    Intent serviceIntent = new Intent(ctx, MyService.class);
    PendingIntent servicePendingIntent =
    PendingIntent.getService(ctx,
    1, // integer constant used to identify the service
    serviceIntent,
    PendingIntent.FLAG_CANCEL_CURRENT); // FLAG to avoid creating a second service
    if (android.os.Build.VERSION.SDK_INT >= 23) {
    am.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, servicePendingIntent);
    }
    }
    else { am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period
    ,interval, servicePendingIntent);

    }

    Any one facing the same issue with marshmallow?Can any one suggest me what i m doing wrong for marshmallow?
     

Share This Page