1. Are you ready for the Galaxy S20? Here is everything we know so far!

Background service stops working on closing app in marshmallow

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

  1. Neha Mittal

    Neha Mittal Lurker
    Thread Starter

    I developed 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?
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...
Similar Threads - Background service stops
  1. persistentone
    Replies:
    2
    Views:
    822
  2. azam216
    Replies:
    10
    Views:
    1,064
  3. Irfan Latif
    Replies:
    1
    Views:
    796
  4. CobaltAxiom
    Replies:
    3
    Views:
    1,219
  5. jebbb24
    Replies:
    3
    Views:
    2,533
  6. AppleUser
    Replies:
    3
    Views:
    2,198
  7. Six dots Software
    Replies:
    26
    Views:
    2,760
  8. VikingGlen
    Replies:
    11
    Views:
    7,113
  9. Sanadel
    Replies:
    7
    Views:
    2,177
  10. Night Knight
    Replies:
    0
    Views:
    2,295

Share This Page

Loading...