I am trying to stop my AsyncTask
when the app exits, but I get the following exception. Where am I wrong? this is my code -
I declare the variable-
private DownloadFileAsync mTask;
then in onDestroy-
@Override
public void onDestroy() {
Log.v("SERVICE", "Service killed");
mTask.cancel(true);
super.onDestroy();
}
03-03 08:57:41.200: E/AndroidRuntime(22678): java.lang.RuntimeException: Unable to stop service com.exe.shark.NSOMUHBroadcastService@d58223c: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.exe.shark.NSOMUHBroadcastService$DownloadFileAsync.cancel(boolean)' on a null object reference