WakefulBroadcastReceiver is deprecated

前端 未结 2 1941
面向向阳花
面向向阳花 2021-02-05 06:57

For creating a receiver I\'m extended WakefulBroadcastReceiver in my old project. But now it\'s deprecated. Instead of WakefulBroadcastReceiver

2条回答
  •  死守一世寂寞
    2021-02-05 07:13

    WakefulBroadcastReceiver Deprecated in API level 26.1.0.

    As of Android O, background check restrictions make this class no longer generally useful. (It is generally not safe to start a service from the receipt of a broadcast, because you don't have any guarantees that your app is in the foreground at this point and thus allowed to do so.) Instead, developers should use android.app.job.JobScheduler to schedule a job, and this does not require that the app hold a wake lock while doing so (the system will take care of holding a wake lock for the job).

    public class JobSchedulerService extends JobService {
    
        @Override
        public boolean onStartJob(JobParameters params) {
    
            return false;
        }
    
        @Override
        public boolean onStopJob(JobParameters params) {
    
            return false;
        }
    
    }
    

    For demo case, Check

    • JobScheduler

提交回复
热议问题