我正在创建一个 APK,但我遇到了问题。我的 APK 完成后会发送一个 GET 请求。我有一个asynctask
定期发送 GET 请求的类。问题是当我再次启动应用程序时,我需要终止前一次启动的后台进程。我把uses-permission android:name="android.permission.RESTART_PACKAGES"
和uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"
放在 manifest.xml 中,并使用了以下代码:
if (URLUtil.isValidUrl(URL_Pet_GET) && URLUtil.isValidUrl(URL_Host)){
//Get_Backgnd.cancel(true); not working
context.getSystemService(Context.ACTIVITY_SERVICE);
manager.killBackgroundProcesses(String.valueOf(process.processName));
//not working
//ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
//activityManager.restartPackage(packageName);
//not working
pet_get_backgrnd Get_Backgnd = new pet_get_backgrnd();
Get_Backgnd.execute(); //Send GET request that I need stop on next execution of apk
}
private class pet_get_backgrnd extends AsyncTask<Context, Object, Object>{
/*@Override
protected void onPreExecute() {
cancel(true);
}*/ //not working
@Override
protected Object doInBackground(Context... params) {
//send Get requests
}
}
如何Get_Backgnd
在下次执行 APK 时取消执行?