我有兩個活動A
和B
其中有一個SharedElement。如果Activity A
開始Activity B
並監聽轉換,則會調用退出和重新輸入的監聽器。瞭解窗口#getSharedElementTransition()
這裏主叫Activity A
代碼:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().getSharedElementReenterTransition().addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
Log.i("Log", "A REENTER");
}
...
});
getWindow().getSharedElementExitTransition().addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
Log.i("Log", "A EXIT");
}
...
});
getWindow().getSharedElementEnterTransition().addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
Log.i("TestApp", "A ENTER");
}
...
});
getWindow().getSharedElementReturnTransition().addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
Log.i("TestApp", "A RETURN");
}
...
});
}
public void onClick(View v){
Intent intent = new Intent(this, Act2.class);
Pair<View, String> pair1 = Pair.create(findViewById(R.id.textView), findViewById(R.id.textView).getTransitionName());
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, pair1);
startActivity(intent, options.toBundle());
}
}
如果現在執行onClick()
(開始Activity B
),然後點擊後退按鈕返回到Activity A
,日誌將如下:
A REENTER
A EXIT
B ENTER
B RETURN
B ENTER
B RETURN
A REENTER
A EXIT
我會想到它是
A EXIT
B ENTER
B RETURN
A REENTER
我的轉換隻包含上面的代碼。所以他們不應該花很長時間。此外,如果我需要在onExit和onReenter期間有可能做不同的事情,那該如何幫助我? [我調整了原來的帖子,以提供更多信息。 ] – AljoSt