How to exit activity at any time, close activity before exiting activity, how to quit all activity of the program

Source: Internet
Author: User

This is a basic problem, no difficulty, just a small logical implementation of the problem. In order to later have the need for convenient, save down. The new study students can refer to the next.

First of all, when writing a project, we usually write baseactivity, which inherits the activity of other activities and inherits Baseactivity.

So, the idea is that we write a activitycollector such a class to add and remove activity, each activity is inherited baseactivity so we can baseactivity the OnCreate method of the current

The activity is added to the collection, and we are removing it when we execute ondestory, so we can remove all the activity from this collection when we have the last interface so that there will be no open activity when you exit with one exit.

Implementation of the Activitycollector class

This class is three ways, I believe we can read and explain

Baseactivity implementation of a simple demo no other logical implementation

The class inherits this class by executing the addition and finsh of the current activity, thus managing the activity.

The activity logic for the three Tests is to inherit baseactivity and then mainactivity inside a button to open the secoundactivity and then secoundactivity Open the third atcivity, the third act Ivity inside a button is used to implement close all, this time you can call Activitycollector's Finshall () method

How to exit activity at any time, close activity before exiting activity, how to quit all activity of the program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.