Always start a new instance of activity without history.

Is there a way to start an action as a new instance without history?

In the manifest file I tried the following.

android:launchmode="singleinstance" android:noHistory=true 

I can achieve what I need, but as soon as the screen is locked, the previous action is displayed. What noHistory should do, but not what I need.

Saving the screen would always be preferable, since it overcharged the battery. Is there any other way to start working with a new instance and not have a history, but also work when the screen is locked?

+4
source share
3 answers

It will begin action with new information and without history.

 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); 
+1
source

You can also do this by adding android:noHistory="true"

in your Android manifest manifest ( ClassName )

+1
source

Try using this flag in the intent.

or Refer This for more info.

 intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 

A new action is not saved on the history stack. As soon as the user moves from him, the action is completed.

0
source

Source: https://habr.com/ru/post/1443481/


All Articles