android - Retry AsyncTask -


For example, I have followed AsyncTask:

  Private class MyAsyncTask extends AsyncTask is; Zero, zero, boolean & gt; {@Override Safe Voice Doine Background (Zero ... Parameter) {try {// Some code which may drop the exception return right; } Hold (IOException east) {return false; }} @ Override Protected Zero on PostXtech (Boolean Ultimate) {if (! Param) {AlertDialog.Builder builder = new AlertDialog.Builder (MyActivity.this); Builder.setMessage ("Error"); Builder. Setup Button ("Retry", New DialogInterface.OnClickListener () {Click on Public Zero (DialogInterface dialogue, int) {// I want to try MyAsyncTask again}}); Builder.setNegativeButton ("Exit", New DialogInterface.OnClickListener () {Click on Public Zero (DialogInterface dialogue, int) {finish ();}}); AlertDialog Warning = Builder.Create (); Alert.show (); }}}   

What is the best practice to do this? I am afraid of repetition of this code.

You "Code" AsyncTask . You have to create a new example and execute it, as you did for the first time, you should not face a recurring problem.

Comments