Quantcast
Channel: Removing an activity from the history stack - Stack Overflow
Viewing all articles
Browse latest Browse all 18

Answer by Travis for Removing an activity from the history stack

$
0
0

This is likely not the ideal way to do it. If someone has a better way, I will be looking forward to implementing it. Here's how I accomplished this specific task with pre-version-11 sdk.

in each class you want to go away when it's clear time, you need to do this:

    ... interesting code stuff ...
    Intent i = new Intent(MyActivityThatNeedsToGo.this, NextActivity.class);
    startActivityForResult(i, 0);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == R.string.unwind_stack_result_id) {
        this.setResult(R.string.unwind_stack_result_id);
        this.finish();
    }
}

then the one that needs to set off the chain of pops from the stack needs to just call this when you want to initiate it:

NextActivity.this.setResult(R.string.unwind_stack_result_id);
NextActivity.this.finish();

Then the activities aren't on the stack!
Remember folks, that you can start an activity, and then begin cleaning up behind it, execution does not follow a single (the ui) thread.


Viewing all articles
Browse latest Browse all 18

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>