Working on an application in android I used the Asynctask class, it works great when I tested it on my Android device running on 2.3.5, but the problem I encountered also does not work for my tablet 4.0.4
During testing, find out that prexecute () is being called, but doInbackground () is not being called, however, doInbackground () is being called on the device (2.3.5).
One of the reasons I believe in the problem is because the Tablet processor is much faster than the processor, so there may be some thread problems, for example, why, to solve this problem, I used some flags and used Thread. sleep () in the do while loop, so when the condition is true, it works, but with no luck, I'm stuck in the loop itself. Here is my code:
MyAsyncTask object = new MyAsyncTask (MainActivity.this); runOnUiThread(new Runnable() { public void run() { try { if (object.isReady() || !object.isStarting()) { return; } object.execute(); do { Thread.sleep(1000); } while (!object.isReady() && object.isStarting()); if(!object.isReady()) { return; } } catch (InterruptedException e) { e.printStackTrace(); } } });
AsynctaskClass:
public class MyAsyncTask extends AsyncTask<Void, Void, Boolean>{ private ProgressDialog dialog; private Context context; private boolean isStarting = false; private boolean isReady = false; public AsyncUpdatesofJquery(Context context) { this.context = context; isStarting = true; isReady = false; } public boolean isStarting() { return isStarting; } public boolean isReady() { return isReady; } @Override protected void onPreExecute() { isStarting = true; isReady = false; dialog = new ProgressDialog(context); dialog.setMessage("Downloading Files, Please wait..."); dialog.show(); } @Override protected Boolean doInBackground(Void... params) { isReady = true; isStarting = false; downloadFiles(context);
source share