我有一個包含主要活動和彈出活動的應(yīng)用程序,如果我留在應(yīng)用程序中就沒有問題。但是,如果彈出活動已打開并且您從最近的屏幕重新進入應(yīng)用程序,則只會顯示彈出活動。如果您然后關(guān)閉它,您不會返回到主要活動,但應(yīng)用程序會完全關(guān)閉。這將打開主活動的彈出活動:intent = new Intent(ctx, popupActivity.class);intent.putExtra("rackName", resultChest.get(2));ctx.startActivity(intent);這是關(guān)閉彈出活動的方法:@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"導(dǎo)致活動在另一個任務(wù)中打開,這導(dǎo)致了我的問題。為了解決這個問題并防止彈出活動打開兩次,我不得不將其android:launchMode = "singleTop"用于彈出活動。
2 回答

拉風(fēng)的咖菲貓
TA貢獻1995條經(jīng)驗 獲得超2個贊
不要使用android:launchMode = "singleInstance"
,它會創(chuàng)建一個新任務(wù)。
添加回答
舉報
0/150
提交
取消