Android activity statck

Source: Internet
Author: User

During Android development, many people use activity statck to simulate the activity stack that is invisible to the android underlying layer.

The advantages and disadvantages are not mentioned much ..

The following is an implementation.

private static Stack<Activity> s_activitiesStack = new Stack<Activity>();public final static void pushActivity(Activity activity) {if (IConfig.MANAGE_ACTIVITYSTACK_MANUALLY) {if (IConfig.DEBUG_ON)Log.v(TAG, "Push activity:" + activity.getClass().getName());s_activitiesStack.push(activity);}}public final static void popActivity() {if (IConfig.MANAGE_ACTIVITYSTACK_MANUALLY) {if (!s_activitiesStack.isEmpty()) {s_activitiesStack.pop();}}}public final static Activity getTopActivity() {if (IConfig.MANAGE_ACTIVITYSTACK_MANUALLY) {if (!s_activitiesStack.isEmpty()) {return s_activitiesStack.peek();}}return null;}public final static void backToActivity(Class activity) {if (IConfig.MANAGE_ACTIVITYSTACK_MANUALLY) {while (!s_activitiesStack.isEmpty()) {Activity a = s_activitiesStack.peek();if (a.getClass().equals(activity)|| a.getClass().equals(HomeActivity.class)) {break;}if (IConfig.DEBUG_ON)Debug.u(TAG, "a.getClass():" + a.getClass().toString());if(a instanceof HotelDetailsActivity){((HotelDetailsActivity)a).back();}else{a.finish();Utils.popActivity();}}}}public final static void exit(Context context, Class luanchActivity) {Intent intent = new Intent();intent.setClass(context, luanchActivity);intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);intent.putExtra(AppConstants.BUNDLEKEY_EXIT, true);context.startActivity(intent);}

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.