Problem : I have say 4 activities A, B, C and D.
A — calls –> B — calls –> C
new activity call is done using startActivityForResult(… , …)
now my problem is that if I simply call finish on activity C, then onActivityResult(…) is called as expected. But I want to finish C and startActivity(D,…);
// Code from C where I’m calling finish().
public void onSettingsClick(View v) {
System.out.println("My Parent ====== "+getParent());
if (getParent() == null) {
setResult(Activity.RESULT_CANCELED, new Intent());
} else {
getParent().setResult(Activity.RESULT_CANCELED,new Intent());
}
finish();
StartActivityUtil.launchSettings(this);// call to Activity D is done here
}
Plz Help me out, have tried different sol. but no luck 🙁
Also I always get getParent() = null
You need to undertand, finish and startActivity are asynchronized methods, means calling these methods, does not indicate that finish would get called, immediately, and then control would go to startActivity, these commands would be added into queue, and as system, will start activity D, without returning results to parent activity, to get rid of this situation, first finish your activity C, and in onActivityResult on B start Activity D according to the condition