Android job scheduler not persisted on reboot

后端 未结 3 627
长发绾君心
长发绾君心 2021-01-02 02:05

I have implemented Job scheduler in my project and it works fine in the case if the app is in background or if the app is killed. But it is not working if the device is rebo

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-02 02:59

    Register a BroadCastReciever for detecting BOOT_COMPLETED.

    
    
        
    
    

    And in your BroadcastReceiver:

    public class StartUpBootReceiver extends BroadcastReceiver {
    
    @Override
    public void onReceive(Context context, Intent intent) {
    
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            Log.d("startuptest", "StartUpBootReceiver BOOT_COMPLETED");
            ...
        }
      }
    }
    

    Once a user runs any activity in your app once, you will receive the BOOT_COMPLETED broadcast after all future boots.

提交回复
热议问题