为了账号安全,请及时绑定邮箱和手机立即绑定

最近屏幕后如何返回上一个活动

最近屏幕后如何返回上一个活动

www说 2021-06-29 17:58:20
我有一个包含主要活动和弹出活动的应用程序,如果我留在应用程序中就没有问题。但是,如果弹出活动已打开并且您从最近的屏幕重新进入应用程序,则只会显示弹出活动。如果您然后关闭它,您不会返回到主要活动,但应用程序会完全关闭。这将打开主活动的弹出活动:intent = new Intent(ctx, popupActivity.class);intent.putExtra("rackName", resultChest.get(2));ctx.startActivity(intent);这是关闭弹出活动的方法:@Overridepublic boolean onTouchEvent(MotionEvent event) {    finish();    return super.onTouchEvent(event);}AndroidManifest.xml:<application    android:allowBackup="true"    android:icon="@mipmap/ic_lchr"    android:logo="@mipmap/ic_lchr"    android:label="@string/app_name"    android:roundIcon="@mipmap/ic_lchr_round"    android:supportsRtl="true">    <activity android:name=".MainActivity"        android:theme="@style/AppTheme">        <intent-filter>            <action android:name="android.intent.action.MAIN" />            <category android:name="android.intent.category.LAUNCHER"/>        </intent-filter>    </activity>    <activity android:name=".popupActivity"        android:theme="@style/popupTheme"        android:launchMode = "singleInstance">    </activity></application>解决方案:正如@RedWolf 提到的,android:launchMode = "singleInstance"导致活动在另一个任务中打开,这导致了我的问题。为了解决这个问题并防止弹出活动打开两次,我不得不将其android:launchMode = "singleTop"用于弹出活动。
查看完整描述

2 回答

?
拉风的咖菲猫

TA贡献1995条经验 获得超2个赞

不要使用android:launchMode = "singleInstance",它会创建一个新任务。


查看完整回答
反对 回复 2021-07-14
  • 2 回答
  • 0 关注
  • 127 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信