onTaskRemoved() not getting called when Home press & kill the app

后端 未结 1 1549
感动是毒
感动是毒 2020-12-14 04:14

This question not duplicate of onTaskRemoved() not getting called in HUAWEI and XIOMI devices

Problem:

When I press home button & kill

相关标签:
1条回答
  • 2020-12-14 04:52

    Based on your use case, you should be able to meet the criteria for the White listing on Android N and above. You can follow this link to Whitelist your app. By requesting this permission, you can relax some restrictions (like accessing network or holding partial lock) implied by Doze mode and Android O. These restrictions are imposed by OS on the app those are not white-listed.

    For Lollipop: Certain manufacturers using cyanogenmod or other custom implementation, could have impact on the intended behavior of START_STICKY. Workaround in this case would be to rely on onDestroy() method of service to:

    1. Restart the service.
    2. Trigger an AlarmManager which will trigger after few seconds and start the service.

    If you use approach 2:

    On normal devices where the START_STICKY behaves as intended, you can use the AlarmManager to check if service is running by:

    1. Maintain a static variable in service to check if service has been started
    2. Cancel the AlarmManager onStartCommand() of the service.
    0 讨论(0)
提交回复
热议问题