我有一个包含主要活动和弹出活动的应用程序,如果我留在应用程序中就没有问题。但是,如果弹出活动已打开并且您从最近的屏幕重新进入应用程序,则只会显示弹出活动。如果您然后关闭它,您不会返回到主要活动,但应用程序会完全关闭。这将打开主活动的弹出活动: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"用于弹出活动。
添加回答
举报
0/150
提交
取消