Suppose I have 2 AsyncTasks A and B.
Let A be:
public class A extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params){
int a = 1;
while(a < 10){
System.out.println(a);
for(int i = 0; i < 400000; i++){
//empty loop, just to spend time
}
a = a+2;
}
}
}
Let B be:
public class B extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params){
int a = 2;
while(a < 10){
System.out.println(a);
for(int i = 0; i < 400000; i++){
//empty loop, just to spend time
}
a = a+2;
}
}
}
I call both of them at my MainActivity like this:
...
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new A().execute();
new B().execute();
}
I expected the result to be some kind of merge (not perfect but somehow merged) between odds and evens, but I'm getting the whole result of A and after the whole result of B, like this:
1
3
5
7
9
2
4
6
8
Can anyone tell me if this is normal?
Is it possible to have multiple AsyncTasks running at the same time? (I think it is, because I know they are like threads)
If it is, what did I do wrong?
Thank you guys.