Resume the Activity instead of Starting if already exists in back stack

这一生的挚爱 提交于 2019-11-29 23:54:45
Nirali

You can add this two lines and try

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Write this in your manifest file inside Activity

<activity
     android:name=".SettingsActivity"
     android:launchMode="singleInstance"
     android:screenOrientation="portrait" >
</activity>

"singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack. Moreover, the device can hold only one instance of the activity at a time — only one such task.

You can use SingleTask or SingleInstance

"singleTask" - The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one.

"singleInstance" - Same as "singleTask", except that the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task.

Refer this link http://developer.android.com/guide/topics/manifest/activity-element.html

Nhut Chau Minh
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

Visit : http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_REORDER_TO_FRONT

Resume Activity from backstack if exists or create a new one if not

android:launchMode="singleTask"

add this line to your app's AndroidManifest.xml and start the activity with a normal Intent.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!