Removing an activity from the history stack

后端 未结 15 1143
[愿得一人]
[愿得一人] 2020-11-22 08:28

My app shows a signup activity the first time the user runs the app, looks like:

  1. ActivitySplashScreen (welcome to game, sign up for an account?)
  2. Activ
15条回答
  •  臣服心动
    2020-11-22 09:12

    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.

提交回复
热议问题