android - Calling startActivity with shared element transition from onActivityResult
问题描述
I'm calling within onActivityResult
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this, imgv, imgv.transitionName).toBundle())
What I expect to happen
activityB to be started and displayed with a shared element transition
What actually happens
activityB is not started/displayed until minimizing the app and reopening it from recents (animation is also not displayed at this point). Without adding the scene transition it works per-usual and calling this from anywhere else in the code works as expected.
I've tried
- runOnUiThread .
postponeEnterTransition()
withstartPostponedEnterTransition()
in second activity.finishAfterTransition()
this results in a flicker and then showing activityB, I don't want to finish activityA but just tried this.- Using
onActivityReenter()
instead, I can't do this as it does not seem to be called when IstartActivityForResult()
in order to use google sign in.
I suspect it has something todo with a race condition with the animation framework
解决方案
onActivityResult()
onStart()
在现代版本的onResume()
Android API之间调用。听起来在您的活动恢复之前启动具有共享元素转换的新活动存在问题。
(我不确定为什么会出现这个问题。也许其他用户可以回答。)
要解决此问题,我建议将信息保存在以下onActivityResult()
位置,然后在以下位置进行查询onResume()
:
private boolean launchNextActivity = false;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (...) {
this.launchNextActivity = true;
}
}
@Override
protected void onResume() {
super.onResume();
if (launchNextActivity) {
launchNextActivity = false;
// do the launch
}
}
推荐阅读
- c++ - 如何释放 new[] 分配的内存?
- javascript - 如何通过json_encode重定向php页面
- mysql - 需要帮助连接 SQL
- c# - 使用 c# 与 java/c++ 比较的 grpc 的性能基准数
- postgresql - 等待状态显示缓冲区引脚
- c - 当 xTicksToWait = portMAX_DELAY 时,xQueueReceive 会失败吗?
- python - python'jwt'模块没有属性'encode'
- java - 限制用户在 java swing 中打开的 jframe 不超过 1 个
- java - 为什么不触发 Firebase 中的 onDisconnect?
- ios - 我可以在 SFSafariViewController 中从 Safari 获取 cookie 吗?