[英]Not returning to parent activity when back pressed
I have 2 activities, A(the root activity) and B which is launched from A. Pressing back from B returns to A except 1 case. 我有2个活动,A(根活动)和B从A发起。从B返回返回A除1例。
If I am in B, go to home screen, launch the app again from recent apps, B comes to foreground but pressing back leads to home screen instead of A.
If I get back to the app by launching from icon and not from recent apps, shows me activity A, which, let's say, is correct(although B should be shown and pressing back from B should lead to A). If I am in B, go to home screen, launch the app again from recent apps, B comes to foreground but pressing back leads to home screen instead of A.
如果我通过从图标而不是从最近的应用程序启动回到应用程序,向我展示了活动A,比方说,这是正确的(尽管应该显示B并且从B向后按应该导致A)。
Acitivity A: 活动A:
<activity android:name=".AudioRecTabsActivity"
android:label="@string/app_name"
android:launchMode="singleInstance">
<!-- android:configChanges="keyboardHidden|orientation">-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Activity B: 活动B:
<activity android:name=".settings.SettingsActivityOld"
android:label="@string/settings_activity_title"/>
Launching act B from A: 从A发起行动B:
intent = new Intent(this, SettingsActivityOld.class);
startActivity(intent);
尝试在活动B中调用Activity#finish() 。它应该从活动堆栈中删除当前活动并返回到上一个活动。
Override backpress method of your B activity and start activity A from there 覆盖B活动的背压方法并从那里开始活动A.
@Override
public void onBackPressed() {
Intent intent = new Intent(this, A.class);
startActivity(intent);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.