本文实例讲述了Android开发之Activity管理工具类。分享给大家供大家参考,具体如下:
这个工具类是对Activity的一些管理,非常适用
package com.maobang.imsdk.util; import java.util.Stack; import android.app.Activity; import android.app.ActivityManager; import android.content.Context; import android.graphics.drawable.Drawable; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView; import android.widget.ImageView; import android.widget.ListView; /** * Activity管理类 * Created by Administrator on 2016/11/24. */ public class ActivityPageManager { private static StackactivityStack; private static ActivityPageManager instance; /** * constructor */ private ActivityPageManager() { } /** * get the AppManager instance, the AppManager is singleton. */ public static ActivityPageManager getInstance() { if (instance == null) { instance = new ActivityPageManager(); } return instance; } /** * add Activity to Stack */ public void addActivity(Activity activity) { if (activityStack == null) { activityStack = new Stack (); } activityStack.add(activity); } /** * remove Activity from Stack */ public void removeActivity(Activity activity) { if (activityStack == null) { activityStack = new Stack (); } activityStack.remove(activity); } /** * get current activity from Stack */ public Activity currentActivity() { Activity activity = activityStack.lastElement(); return activity; } /** * finish current activity from Stack */ public void finishActivity() { Activity activity = activityStack.lastElement(); finishActivity(activity); } /** * finish the Activity */ public void finishActivity(Activity activity) { if (activity != null) { activityStack.remove(activity); activity.finish(); activity = null; } } /** * finish the Activity */ public void finishActivity(Class<&#63;> cls) { for (Activity activity : activityStack) { if (activity.getClass().equals(cls)) { finishActivity(activity); } } } /** * finish all Activity */ public void finishAllActivity() { if(activityStack!=null&&activityStack.size()>0) { for (int i = 0, size = activityStack.size(); i
更多关于Android相关内容感兴趣的读者可查看本站专题:《Android编程之activity操作技巧总结》、《Android开发入门与进阶教程》、《Android视图View技巧总结》、《Android文件操作技巧汇总》、《Android资源操作技巧汇总》及《Android控件用法总结》
希望本文所述对大家Android程序设计有所帮助。