I am creating an APK but I have a problem. My APK sends a GET request when it finishes. I have a asynctask class for sending a GET request (GPS). The problem is that when I start the application again I need to kill the background processes of the previous launch. I put uses-permission android:name="android.permission.RESTART_PACKAGES" and uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" in the manifest.xml, and used the following code:
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
}
}
How can I cancel the execution of Get_Backgnd on the next execution of the APK? or same How can I cancel the execution of Get_Backgnd of the previous execution of the APK?
Thanks