OnActivityResult not called when using Lollipop activity transitions
In the onCreate method of my HomeActivity I check if the user is logged in, and if not, the LoginActivity is started. If I start LoginActivity without transitions using:
startActivityForResult(intentLogin, INTENT_REQUEST_LOGIN);
everything is fine, onActivityResult is called as planned when I call finish () in LoginActivity. But if I use:
ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(this);
startActivityForResult(intentLogin, INTENT_REQUEST_LOGIN, activityOptionsCompat.toBundle());
and call ActivityCompat.finishAfterTransition () in LoginActivity accordingly, onActivityResult will never be called in HomeActivity.
The transitions to LoginActivty are set as follows:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if (Utils.isRunningLollipopAndHigher()) {
setActivityTransition();
}
...
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setActivityTransition() {
Transition transitionEnter = new Slide(Gravity.BOTTOM);
transitionEnter.excludeTarget(android.R.id.statusBarBackground, true);
transitionEnter.excludeTarget(android.R.id.navigationBarBackground, true);
getWindow().setEnterTransition(transitionEnter);
}
I terminate LoginActivity with:
private void finishLogin() {
setResult(RESULT_OK);
ActivityCompat.finishAfterTransition(this);
}
The transitions themselves work fine. Any pointers what could be the problem with onActivityResult?
Thank!
EDIT: Ok, after running some tests, it looks like starting an activity with transitions and forResult during the activity lifecycle always results in onActivityResult not being called. If I run LoginActivity eg. after clicking the button, everything works as expected.
source to share
No one has answered this question yet
Check out similar questions: