android clears the activity in the previous task

There is a scenario in the development process: close all the activities before, and jump to the login page. In the

past , the activities were all placed in a list. When exiting the application, traverse the list and finish one by one.

Change the implementation method. Add two flags to the intent of

jumping  the login page.
Intent.FLAG_ACTIVITY_CLEAR_TASK

Intent.FLAG_ACTIVITY_NEW_TASK

	Intent intent = new Intent(this, TestCActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivity(intent);




Of course, if the launchMode of the login page is singleTask, you don't need to
Intent.FLAG_ACTIVITY_NEW_TASK

(Either declare it in the manifest file, or add a flag to the intent, either)

See the google documentation
     * If set in an Intent passed to {@link Context#startActivity Context.startActivity()},
     * this flag will cause any existing task that would be associated with the
     * activity to be cleared before the activity is started.  That is, the activity
     * becomes the new root of an otherwise empty task, and any old activities
     * are finished.  This can only be used in conjunction with {@link #FLAG_ACTIVITY_NEW_TASK}.


The basic of cet-4 can be understood~

Note that the api level should be greater than 11

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326591818&siteId=291194637