views:

720

answers:

1

So I have a huge maze of activities in my application. What I need to do, is that when the user logs in into the system, the activity history should be cleared. I cant just use finish() when I start a new activity, because I want the activities to have a history until the user logs in. I have experimentet with the different flags when starting an activity, but I have had no success. Any ideas?

Cheers,

A: 

I might as well reveal the hax I am currently using to solve my problem. On the "pre-logged in" activities, I have set this in the manifest:

android:noHistory="true"

Then in each activity 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 super.onKeyDown(keyCode, event);
    }
    return super.onKeyDown(keyCode, event);
}

The FLAG_ACTIVITY_NO_ANIMATION only works on phones with API level 5 or higher, but what it does is that instead on the "open new activity"-animation, the "going back to previous activity"-animation is played (atleast on the droid and nexus). This prevents the confusing appearence that a new activity is started when the user presses the back-button.

This solution is not perfect. On phones with a API-level lower then 5 the animations becomes incorrect. Also, it is not super neat and requires more code then I prefer. Still, it works...

sandis