All you need is the following line of code (there must be others), but of course there are limitations (. The man. And just quit the current task!
BackFlow.finishTask(activity | fragment)
In fact, I made an open source project (^__^), take it out for everyone to appreciate, welcome your comments
Project: github.com/xuyt11/andr… Welcome to star.
Function: a tool to control the rollback of Android views (Activities and Fragments).
Tip: This is a rollback tool, not a jump tool
solution
StartActivityForResult, onActivityResult, setResult, and Finish (Activity) are used.
If we call the startActivityForResult method every time, then we can use setResult and Finish (Activity), Intercepts setResults of type finish_Task in the onActivityResult method of the previous view, and then setResult and Finish (Activity), so that the view can be chained back until the last activity, When all activities finish, the App exits!
limit
Of course, there are limitations to this. If any XXXActivity in the middle of the rollback chain consumes the onActivityResult method, it stays in that XXXActivity and cannot continue the rollback.
Because the entire rollback function relies on the setResult method to cascade back data to the previous activity’s onActivityResult method, it is never called again after the activity has consumed the onActivityResult method.
Examples of cases that consume the onActivityResult method are as follows:
1. Switch tasks;
2. Switch process;
Intent.setflags (intent.flag_activity_new_task);
Therefore, it can only be used in the context of Single Task && Single Process.
For more details, please visit the following page: Welcome to follow, favorites, like and star
www.v2ex.com/t/333969
Github.com/xuyt11/andr…