Android job scheduler not persisted on reboot

后端 未结 3 620
长发绾君心
长发绾君心 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:39

    You need to call the setPersisted(boolean isPersisted) method.

    You can find it in the doc https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setPersisted(boolean)

    0 讨论(0)
  • 2021-01-02 02:59

    Register a BroadCastReciever for detecting BOOT_COMPLETED.

    <receiver android:name="com.example.startuptest.StartUpBootReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
    

    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.

    0 讨论(0)
  • 2021-01-02 03:01

    I know it is an old question, and you probably already have the solution, but the issue likely was, that JobService caches the UUIDs of the apps that have the permission. You will need to reinstall your app and it is gonna be alright.

    Source: https://android.googlesource.com/platform/frameworks/base/+/5d34605/services/core/java/com/android/server/job/JobSchedulerService.java

    0 讨论(0)
提交回复
热议问题