Implementation method for Android to close multiple activities

Implementation method for Android to close multiple activities

In general, there are four methods:

1. Use application to close

2. Use broadcast to turn off

The registration broadcast is implemented in the base class constructor, and the ondestroy method cancels the registration

Next, you just need to call the interface where you want to close all activities

3. Close using onactivityresult recursive callback

1) Override the onactivityresult method in the base class activity and call the finish method by identifying the resultcode

2) Next, just call setresult (result_close) when you want to close the activity

4. Use setfalls to close

First, let's introduce four modes of a launchmode:

LaunchMode

1) Standard and singletop are the same. A new activity instance will be created every time. The difference is that singletop will not create an instance when the activity pushed into the stack is the same as the activity at the top of the task stack (the onnewintent method will be called)

2) Singleinstance and singletask are the same, which will ensure that there are no same tasks in the task (when the executing activity is the same as an activity in the task, the onnewintent method will be called). The difference is that (singleinstance will create a task stack and push the activity into the stack every time), (single task is in a task stack. If the activity pushed into the stack is the same as one in the stack, the activity will be directly moved to the top of the stack without creating a new instance.)

Of course, these four modes are not used here, but intent.flag is used_ ACTIVITY_ CLEAR_ Top, which is basically similar to singletop. The difference is that if the activity pushed into the stack is the same as an activity in the stack, all the activities above it will be out of the stack.

Add it to every jump

Therefore, in the last activity, you can back up the application:

This is a little complicated. Now let's talk about another method of using flag:

Jump to the previous activity of the exited activity and add

OK, now what do these mean

If you have any questions, please leave a message or go to the community of this site for communication and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>