我正在尝试将
这是我启动活动的方式: Intent intent = new Intent(activity, LoginActivity.class);
TransitionListener
添加到默认的活动转换中,像这样:@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getEnterTransition().addListener(new TransitionAdapter());
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private class TransitionAdapter implements Transition.TransitionListener {
@Override
public void onTransitionStart(Transition transition) {
Log.i("transition", "onTransitionStart");
}
@Override
public void onTransitionEnd(Transition transition) {
Log.i("transition", "onTransitionEnd");
}
@Override
public void onTransitionCancel(Transition transition) {
Log.i("transition", "onTransitionCancel");
}
@Override
public void onTransitionPause(Transition transition) {
Log.i("transition", "onTransitionPause");
}
@Override
public void onTransitionResume(Transition transition) {
Log.i("transition", "onTransitionResume");
}
}
这是我启动活动的方式: Intent intent = new Intent(activity, LoginActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Bundle options = ActivityOptions.makeSceneTransitionAnimation(activity).toBundle();
activity.startActivityForResult(intent, RequestCodes.SIGN_IN, options);
} else {
activity.startActivityForResult(intent, RequestCodes.SIGN_IN);
}
问题在于真机上没有任何回调被调用。但在genymotion上是可以运行的。是否需要进行其他设置?
免责声明:我在运行lolipop设备上测试了它。
ActivityOptions.makeSceneTransitionAnimation(activity).toBundle()
在Genymotion上有效,但在真机上无效。 - Jacek Kwiecień