Monday, April 8, 2013

[android help] Android restart AsyncTask


I am having some trouble restarting an AsyncTask after I try to reopen the activity.


When I first open the activity I call this to start the AsyncTask which works the very first time.



myTask connectedTask;
connectedTask = new myTask();
connectedTask.execute();

public class myTask extends AsyncTask {

@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 previous activity and try to start that activity again I can't get the AsyncTask to start again.


I read that as long as I create a new instance of the AsyncTask I should be to restart those tasks.


Is there something else that I should be doing?


Thank you,



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...