I'm trying to use the new API for activity transition only on lollipop (I'm using the compact version tho), so I'm implementing an animation from activity A to activity B, in Activity A:
getWindow().setReenterTransition(null);
getWindow().setExitTransition(null);
getWindow().setAllowEnterTransitionOverlap(false);
getWindow().setAllowReturnTransitionOverlap(false);
because I'm not interested in enter or exit of this activity, the only animations that I want to see are in the shared view with the Activity B.
For launching Activity B:
ActivityCompat.startActivity(this, intent, ActivityOptionsCompat.makeSceneTransitionAnimation(this, fabButton, getString(R.string.transition_fab)).toBundle());
And the setup of Activity B:
getWindow().setEnterTransition(new EmptyTransition());
getWindow().setReturnTransition(null);
getWindow().setAllowEnterTransitionOverlap(false);
getWindow().setAllowReturnTransitionOverlap(false);
getWindow().getEnterTransition().addListener(listener).
Again I'm not interested in the enter transition of return transition because the content is hidden till the enter transition listener method 'onTransitionEnd' is called, so my transition it's all based on the shared element which move/grow from Activity A to Activity B and when this transition is finished I'm bringing the content in.
Everything works fine, but on not very powerful devices (so all non-Nexus) from time to time the Activity A silently crash with:
java.lang.RuntimeException: Performing stop of activity that is not resumed: {com.transferwise.android.debug/com.transferwise.android.activity.LoggedInMainActivity}
And the transition of the shared element happens but then the listener is not called (not event TransitionStart), so the content doesn't enter. The app is not crashing, user can still press back and "try again" but it's not a very good UX.
It's difficult to test it because it happens once every 10/20 times and only on some specific devices (it happens more on a Sony Xperia Z3 compact).
Also:
Danieles-MacBook-Pro-2:~ danielebottillo$ adb shell dumpsys activity p | grep com.package.main.debug
*APP* UID 10349 ProcessRecord{3b27508d 18371:com.package.main.debug/u0a349}
dir=/data/app/com.package.main.debug-1/base.apk publicDir=/data/app/com.package.main.debug-1/base.apk data=/data/data/com.package.main.debug
packageList={com.package.main.debug}
- ActivityRecord{2f07bdf8 u0 com.package.main.debug/com.package.main.activity.ActivityA t1196}
- ActivityRecord{1e871eb3 u0 com.package.main.debug/com.package.main.activity.ActivityB t1196}
- 28ea3e28/com.android.providers.settings/.SettingsProvider->18371:com.package.main.debug/u0a349 s1/1 u0/0 +27m9s645ms
- ReceiverList{40f2178 18371 com.package.main.debug/10349/u0 remote:39e102db}
- ReceiverList{2e7456a6 18371 com.package.main.debug/10349/u0 remote:dde3801}
- ReceiverList{39e2f1b7 18371 com.package.main.debug/10349/u0 remote:362300b6}
- ReceiverList{3afa7bd5 18371 com.package.main.debug/10349/u0 remote:33e4088c}
Proc # 0: fore F/A/T trm:10 18371:com.package.main.debug/u0a349 (top-activity)
PID #18371: ProcessRecord{3b27508d 18371:com.package.main.debug/u0a349}
An Android activity goes through six major lifecycle stages or callbacks. These are: onCreate() , onStart() , onResume() , onPause() , onStop() , and onDestroy() . The system invokes each of these callbacks as an activity enters a new state.
When Android starts an activity, it calls its onCreate() method. onCreate() is always run whenever an activity gets created.
onCreate() It is called when the activity is first created. This is where all the static work is done like creating views, binding data to lists, etc. This method also provides a Bundle containing its previous frozen state, if there was one.
Activity or dialog appears in foregroundWhen the covered activity returns to the foreground and regains focus, it calls onResume() . If a new activity or dialog appears in the foreground, taking focus and completely covering the activity in progress, the covered activity loses focus and enters the Stopped state.
Judging from other answers here, I can see a couple of possibilities.
Memory: it's possible that the device is running low on memory, so Android is killing non-foreground activities. Perhaps it's trying to do something with fabButton
after Activity A is killed. Can you slim down your memory consumption and see if that reduces or eliminates the problem?
Lifecycle: if you're transitioning from Activity A to Activity B from within Activity A's onStart()
method, then Activity A might be killed before it ever gets to run onResume()
. If you have any significant code in onStart()
, try moving it to onResume()
instead. That should prevent Activity A from getting killed before it gets to onResume()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With