实际上我想使用 JobScheduler 进行通知,无论应用程序是否处于活动状态。我是 android 新手,首先只是尝试运行后台 AsyncTask 来检查它是否工作正常,但它不起作用。
这是我的 JobService 代码:
public class JobSchedularClass extends JobService {
private static final String TAG = "JobSchedularClass";
private BackgroundJob backgroundJob;
@Override
public boolean onStartJob(final JobParameters params) {
Log.d(TAG, "onStartJob: ");
backgroundJob=new BackgroundJob(){
@Override
protected void onPostExecute(String s) {
Toast.makeText(getApplicationContext(),s+"kjk",Toast.LENGTH_SHORT).show();
jobFinished(params,false);
}
};
backgroundJob.execute();
return true;
}
@Override
public boolean onStopJob(JobParameters params) {
Log.d(TAG, "onStopJob: ");
backgroundJob.cancel(true);
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
异步任务类:
public class BackgroundJob extends AsyncTask<Void,Void,String> {
private static final String TAG = "BackgroundJob"; …Run Code Online (Sandbox Code Playgroud)