I have completed 2 asyn tasks, I am using android4.0. where one asyntase is performed continuously, the second is performed based on the requirement (may be mulitpe time). For instance.
class AsynTask1 exetends AsyncTask<Void, Bitmap, Void>{ protected Void doInBackground(Void... params) { while(true){ publishProgress(bmp); } } } class AsynTask2 extends AsyncTask<String, Void,Void>{ protected Void doInBackground(String... params){ System.out.println(params[0]) } }
In activity class
class MainActivity extends Activity{ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); new AsynTask1().execute(); int i=0; while(i<100) { if(i%2==0) new AsynTask2().execute("no is even"+i); i++ } } }
In the above case, AsynTask2 fails.
If you try to execute executeOnExecutor (AsyncTask.THREAD_POOL_Executor, params), then both asyntask are executed and I get print messages from AsynTask2, but they are not ok (for example, 0 2 6 4 10 8 12 14 ....).
Is there a way to continuously execute AsynTask1 and AsynTask2 in sequential order to prevent (e.g. 0 2 4 6 8 10 12 14 ....).
Thank you and respectfully mini.
source share