Android learning-how to disable all activities

Source: Internet
Author: User

Activity declaration cycle
Method 1
We know that the window class of Android provides a historical stack, and we can implement it skillfully through the stack principle. Here we add the intent icon directly to window a when window a opens window B. flag_activity_clear_top. When B is enabled, all activities in the process space are cleared.

Use the followingCodeCall window B
Java code

Intent intent = new intent ();
Intent. setclass (android123.this, cwj. Class );
Intent. setflags (intent. flag_activity_clear_top); // pay attention to the flag settings of the row.
Startactivity (intent)

 

Method 2:

Write in the call exit Method

Myapplication. getinstance (). Exit ();

Public class myapplication extends application {

Private list <activity> activitylist = new shortlist <activity> ();
Private Static myapplication instance;

Private myapplication (){
}

// Obtain the unique myapplication instance in singleton Mode
Public static myapplication getinstance (){
If (null = instance ){
Instance = new myapplication ();
}
Return instance;

}

// Add the activity to the container
Public void addactivity (activity) {
activitylist. add (activity);
}

// traverse all the activities and finish
/*
* in each activity in the oncreate method, add the activity to the container of the myapplication object instance
* myapplication. getinstance (). addactivity (this );
* call the exit method when you want to end all activities.
*
* myapplication. getinstance (). exit ();
*/
Public void exit () {

For (activity: activitylist ){
Activity. Finish ();
}

System. Exit (0 );

}

Related Article

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: info-contact@alibabacloud.com 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.