Is it possible that activity (which is called finish) start some other activity?

Viewed 44

Is it possible that activity (which is called finish) start some other activity?

like below code?

        Intent intent = new Intent(activity, OtherActivity.class);

        activity.finish();
        activity.startActivity(intent);
2 Answers

Yes, in fact sometimes you do this on purpose. The result of this would be to remove the current activity from the backstack, and start OtherActivity. Splash screens and login screens frequently do this, especially if the login screen isn't just at the start of the app, but pops up as a result of a timeout.

You can test your own code, you will find that this is feasible, because finish needs to run for a while, but usually first execute startActivity and then execute finish.

Related