how to start method B()(main thread) inside onResume() after method A()(work thread) finished inside onStart()
I have loadCards() inside onStart(), and initViews() inside onResume().
Need to run initViews() only after loadCards() finished, loadCards() is a long-running operation, and have a callback().
Current problem is initViews() runs before loadCards() finished, so get a null pointer.
Would like to get help: how to run initViews()(inside onResume) only after loadCards()(inside onStart) has finished?
@Override
protected void onStart() {
super.onStart();
loadCards(new Callback(){
success(List<Card> cardList){do something}
fail(){do other thing}
});
}
@Override
protected void onResume() {
super.onResume();
//my problem is here:
//how to know if loadCards() has finished? then run initViews.
initViews();
}
public void loadCards(Callback callback) {
Runnable runnable = () -> {
//List<Card> cardList = get list from work thread;
mAppExecutors.mainThread().execute(() -> {
if (result == empty) {
callback.fail();
} else {
callback.success(cardList);
}
});
};
mAppExecutors.diskIO().execute(runnable);
}
void initViews(){}
expected: after loadCards() has finished, run initViews().
actual: when loadCards() is still running, initViews() runs.