Reputation: 45
I have 3 public voids. The first void parse a pdf file. The second void enhance that pdf file into a string , and the third void uses that string in order to display textviews programmatically (in a for-loop). When all of these voids are called, the app crashes since they're all trying to run at the same time. I want them to wait for each other to complete their task. I don't wanna create a single large void with all the components in it.
How can I call them so that they wait for each other to finish?
Upvotes: 0
Views: 57
Reputation: 392
Try to use Runnable array
Array:
Runnable[] methods = new Runnable[]{
new Runnable() {
@Override
public void run() {
Log.d("TAG", "1");
//1 method
}
},
new Runnable() {
@Override
public void run() {
Log.d("TAG", "2");
//2 method
}
},
new Runnable() {
@Override
public void run() {
Log.d("TAG", "3");
//3 method
}
}
};
Call to it:
ExecutorService service = Executors.newSingleThreadExecutor();
for (Runnable r : methods)
service.submit(r);
service.shutdown();
Upvotes: 2