Start activity and clear activity history

So, I have a huge maze of actions in my application. What I need to do is that when the user logs in, the history of operations should be cleared. I can't just use finish () when I start a new action, because I want the actions to have a history until the user logs in. I have an experiment with different flags when starting an activity, but I have not been successful. Any ideas?

Greetings

+6
android android-activity
source share
2 answers

I could also uncover hax, which I am now using to solve my problem. In the "pre-logged in" actions, I set this in the manifest:

android:noHistory="true" 

Then in every action I have this code:

 public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { Intent intent = new Intent(MyActivity.this, ParentActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent); return true; } return super.onKeyDown(keyCode, event); } 

FLAG_ACTIVITY_NO_ANIMATION only works on phones with API level 5 or higher, but what it does is that instead of “open new activity”, the animation plays “return to previous activity” (at least on the droid and communication) . This prevents the confusion of the appearance of a new action when the user presses the back button.

This solution is not perfect. On phones with an API level lower than 5, the animation becomes incorrect. Also, it is not super neat and requires more code than I prefer. However, it works ...

+2
source share

you can use 65536 instead of Intent.FLAG_ACTIVITY_NO_ANIMATION for earlier versions

+1
source share

All Articles