This happens whether I call finish()
or use the hardware back button.
This is happening on 4.4.2 x86 AVD emulator, but not physical 5.1.1 device.
This only happens in landscape mode for some reason.
I can recreate this by following the exact steps repeatedly, but I have not been able to create a minimal example yet, trimming out all my companies private information.
I was certain I had seen some reference to this, on stack overflow in the past, but I cannot find it.
I have found one suspect activity launch in my application, that uses getApplicationContext().startActivity(i);
with flag FLAG_ACTIVITY_NEW_TASK
The flow that creates this is
MainActivity
) FLAG_ACTIVITY_NEW_TASK
) FLAG_ACTIVITY_CLEAR_TOP
, and re-starts MainActivity
) FLAG_ACTIVITY_NEW_TASK
, but I CANNOT recreate this in portrait ) Back
or hit the save button that calls finish()
; The only difference I can see using adb shell dumpsys activity activities
is one entry that shows when that last fragment is loaded, this value has changed:
Hist #3: ActivityRecord{b4410058 u0 <package>/<DetailActivity> t20} packageName=<package> processName=<package> launchedFromUid=10058 launchedFromPackage=<package> userId=0 app=ProcessRecord{b43f4040 4154:<package>/u0a58} Intent { cmp=<package>/<DetailActivity> (has extras) } **frontOfTask=false** task=TaskRecord{b43ced20 #20 A=<package> U=0 sz=4}
And this also changes mFocusedStack=ActivityStack{b44a83a0 stackId=10, 1 tasks} mStackState=STACK_STATE_HOME_TO_FRONT
As I mentioned, I have tried creating a minimal example, but when I luch all the activities in the same order in a Test App ( that does not do any of my network transactions etc. ), the issue is not visible.
TL:DR; Sometimes in landscape mode, finishing an activity takes me to device home, instead of the previous activity - This is with finish()
or the device back button.
And to point out again - this ONLY happens when I combine running the activity 100% in landscape from start to finish ( no rotation ), and when I log out and log back in.
I do not see any items in the log about using too much memory.
As a test to eliminate some recommendations, I did put android:configChanges="keyboardHidden|orientation|screenSize"
back on every activity, and I do get the same behavior
I will note that all of our fragments in my application are retained, but I am not getting any errors about out of memory, but it's a thought.
I implemented one for my project. May be this could be of some help to you (note: I used only portrait mode). In my project, I had one activity which triggered multiple fragments. When user presses back button, I wanted to go back in the same order. Here is my implementation.
Add the fragments to backstack:
private void FragmentCommit(FragmentTransaction transaction, Fragment fragment, String fragmentTagName){
transaction
.replace(R.id.main_activity_fragment, fragment, fragmentTagName)
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
.transaction.addToBackStack(fragmentTagName)
.commit();
}
In the Activity, I overrode onBackPressed():
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
}
else {
FragmentManager fragmentManager = getSupportFragmentManager();
if(fragmentManager.getBackStackEntryCount()>1){
fragmentManager.popBackStack();
}
else{
super.onBackPressed();
}
}
}
I am checking for > 1 since I always had the first fragment as my home page.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.