我有3个活动:Main,B,C
我的清单:
<activity
android:name="com.test.one.MainActivity"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".B"
android:parentActivityName=".MainActivity">
</activity>
<activity android:name=".C"
android:parentActivityName=".MainActivity">
</activity>
我开始活动B:
Intent intent = new Intent(this, B.class);
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(this,
imageView,
ViewCompat.getTransitionName(imageView));
ActivityCompat.startActivityForResult(this, intent, 666, options.toBundle());
共享元素过渡工作正常,然后我开始活动C:
Intent intent = new Intent(this, C.class);
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(this,
imageView,
ViewCompat.getTransitionName(imageView));
ActivityCompat.startActivity(this, intent, options.toBundle());
共享元素过渡也可以正常工作,然后我想返回父级MainActivity:
Intent intent = new Intent(this, MainActivity.class);
setResult(666);
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(this,
imageView,
ViewCompat.getTransitionName(imageView));
ActivityCompat.startActivity(this, intent, options.toBundle());
这里我有一个问题:onActivityReenter没有被调用,共享元素转换不起作用:
我还尝试过此操作以返回MainActivity:
setResult(666);
NavUtils.navigateUpFromSameTask(this);
但结果相同:应用了默认过渡。 有什么想法可以使过渡有效吗?