有沒有辦法將活動作爲沒有歷史記錄的新實例啓動?始終啓動沒有歷史記錄的新活動實例
在清單文件中嘗試了以下內容。
android:launchmode="singleinstance"
android:noHistory=true
我能夠實現我所需要的,但只要屏幕鎖定,就會顯示先前的活動。這就是noHistory
應該做的,但不是我所需要的。
保持屏幕始終不會更好,因爲它會不必要地耗盡電池。有沒有其他的方式來開始一個新的實例的活動,沒有歷史,但也可以在屏幕鎖定時工作?
有沒有辦法將活動作爲沒有歷史記錄的新實例啓動?始終啓動沒有歷史記錄的新活動實例
在清單文件中嘗試了以下內容。
android:launchmode="singleinstance"
android:noHistory=true
我能夠實現我所需要的,但只要屏幕鎖定,就會顯示先前的活動。這就是noHistory
應該做的,但不是我所需要的。
保持屏幕始終不會更好,因爲它會不必要地耗盡電池。有沒有其他的方式來開始一個新的實例的活動,沒有歷史,但也可以在屏幕鎖定時工作?
這將啓動新的信息,並沒有歷史
Intent intent = new Intent(MainActivity.this, TargetActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
MainActivity.startActivity(intent);
嘗試意圖使用此標誌的活動。
或推薦本爲More Detail
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
新的活動沒有保存在歷史堆棧。只要用戶離開它,活動就完成了。
您也可以做到這一點在你的Android清單活動代碼添加android:noHistory="true"
(ClassName
)
嘗試了上面的android:launchmode = single_instance以及nohistory但仍是無法得到所需的結果。 – banditpoper