Background Service stop after power saver enable a

2019-07-11 18:08发布

I have an application in which I perform some task in background,

So the task will perform if my background service is running

Problem : When I enable and disable power saver, so it close everything and stop every background services which are running. After turning off power saver the service is not getting start till I open the application.

So how I can restart my background service when power saver off for lower version than Android.M

Facing issue in Android 6.0 and below.

Myservice.java

public class Myservice extends Service {

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

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public boolean stopService(Intent name) {
        return true;
    }
}

I Start this service is my MainActivity.java

So I can get any kind of broadcast or notification of power saver

0条回答
登录 后发表回答