Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Handling back button during asynctask
    text
    copied!<p>I have an Activity that shows a listview. On item click a second activity is started which runs an AsyncTask that fetches a remote URL based on which item is clicked, parses the results, then displays those results into another list view. While the async task is running I have a "loading" view that just displays an image and text. The problem is if I initiate the activity that runs the async task, then press back and start another instance of said activity, I get a force close.</p> <p>I have tried <pre>private class getlist extends AsyncTask implements OnDismissListener{ ... @Override public void onDismiss(DialogInterface arg0) { this.cancel(true); } }</pre></p> <p>But the problem persists.</p> <p>I have also put</p> <pre> if(!isCancelled()){ setContentView(R.layout.list); ... etc. } </pre> <p>into my onPostExecute call, but either this is not preventing the view from being switched, or the problem is something else.</p> <p>logcat shows "unexpected resume while already resumed .. got RemoteException sending setActive(false) notification" Then a bit further down in the log, "java.net.SocketTimeoutException: Socket is not connected"</p> <p>How can I resolve this?</p> <p>update:</p> <pre> E/AndroidRuntime(19379): Uncaught handler: thread AsyncTask #2 exiting due to uncaught exception E/AndroidRuntime(19379): java.lang.RuntimeException: An error occured while executing doInBackground() E/AndroidRuntime(19379): at android.os.AsyncTask$3.done(AsyncTask.java:200) E/AndroidRuntime(19379): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) E/AndroidRuntime(19379): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) E/AndroidRuntime(19379): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) E/AndroidRuntime(19379): at java.util.concurrent.FutureTask.run(FutureTask.java:137) E/AndroidRuntime(19379): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) E/AndroidRuntime(19379): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) E/AndroidRuntime(19379): at java.lang.Thread.run(Thread.java:1096) E/AndroidRuntime(19379): Caused by: java.lang.NullPointerException E/AndroidRuntime(19379): at com.metatroid.android.swim.ThreadViewer.getPosts(ThreadViewer.java:153) E/AndroidRuntime(19379): at com.metatroid.android.swim.ThreadViewer$getlist.doInBackground(ThreadViewer.java:70) E/AndroidRuntime(19379): at com.metatroid.android.swim.ThreadViewer$getlist.doInBackground(ThreadViewer.java:1) E/AndroidRuntime(19379): at android.os.AsyncTask$2.call(AsyncTask.java:185) E/AndroidRuntime(19379): at java.util.concurrent.FutureTask$Sync.innerRun</pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload