I am having trouble restarting AsyncTask
after trying to reopen the activity.
When I first open the action, I call it to launch AsyncTask
, which works for the first time.
myTask connectedTask; connectedTask = new myTask(); connectedTask.execute(); public class myTask extends AsyncTask<Integer,Integer, Integer> { @Override protected Integer doInBackground(Integer... arg0) { //Increase timer and wait here in a loop System.out.println("ASYNC TASK STARTING!"); return IsSocketConnected(); } protected void onPostExecute(Integer result) { //Something you want to do when done? System.out.println("ASYNC TASK DONE!"); // if it was connected successfully if(result == 1) { // remove the progress bar proBar.setVisibility(View.GONE); // Discover available devices settings and create buttons CreateButtons(btnList); } } } IsSocketConnected(); // checks for a bluetooth connections to be done.
When I go back to the previous action and try to start this operation again, I cannot start AsyncTask
to start again.
I read that while I create a new instance of AsyncTask
, I have to restart these tasks.
Is there anything else I should do?
Thanks,
source share