Use stackmanager to manage the Android app activity by yourself

Source: Internet
Author: User

Use stackmanager to manage the Android app activity by yourself

Directly Add code

Package COM. example. test; import Java. util. hashmap; import Java. util. iterator; import Java. util. map; import Java. util. stack; import android. app. activity; public class stackmanager {// stack manager stackmanager instance Private Static stackmanager instance; // stack is a type of data structure (LIFO) that stores stacks of a series of objects. You can perform pop and push operations on the stack, even if it is a null object, and the stack has no size to display the stack <activity> activitystack = new stack <activity> (); map <string, activity> mapstack = new hashmap <string, activity> ();/*** obtain the instance in singleton mode * @ return */Public synchronized static stackmanager getinstance () {If (instance = NULL) instance = new stackmanager (); Return instance ;} /*** add activity to stack to prepare for exit ** @ Param activity */Public void pushtostack (Activity Activity) {If (activity! = NULL) activitystack. add (activity);}/*** clear all the activities in the stack */Public void popallforexit () {for (Activity E: activitystack) E. finish (); activitystack. clear ();}/*** add activity to the stack to prepare for the navigation area ** @ Param key * @ Param activity */Public void pushtomapstack (string key, activity) {If (! Mapstack. containskey (key) mapstack. put (Key, activity);} public void popallforstartactivity (string key) {iterator <string> iterator = mapstack. keyset (). iterator (); While (iterator. hasnext () {string K = iterator. next (); If (! K. equals (key) {mapstack. get (k ). finish (); mapstack. remove (k); iterator = mapstack. keyset (). iterator ();}}}}

If the project needs to be added, it is OK.

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.