退出登录并finish所有的activity

退出登录处理把token信息清理掉还需要把activity finish掉。方法有很多种我采取的是把所有activity放在集合里面统一处理

创建一个baseactivity 所有的activity都继承他

/**
 * Created by wjs on 2017/3/24.
 */
public class BaseActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityManage.addActivity(this);
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityManage.removeActivity(this);
    }

添加删除activity的方法

/**
 * Created by wjs on 2017/3/24.
 * activity的管理类
 */
public class ActivityManage {
    public static List activities = new ArrayList();

    public static void addActivity(Activity activity) {
        activities.add(activity);
    }

    public static void removeActivity(Activity activity) {
        activities.remove(activity);
    }

    public static void finishAll() {
        for (Activity activity : activities) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
    }
}

在需要的地方调用

ActivityManage.finishAll();



你可能感兴趣的:(android)