zoukankan      html  css  js  c++  java
  • 关于 android 一键退出的实现

    1.编写一个class继承Application
    public class AppClose extends Application {

        private List<Activity> mainActivity = new ArrayList<Activity>();
        public List<Activity> MainActivity() {
                return mainActivity;
        }
        public void addActivity(Activity act) {
                mainActivity.add(act);
        }
        public void finishAll() {
                for (Activity act : mainActivity) {
                        if (!act.isFinishing()) {
                                act.finish();
                        }
                }
                mainActivity = null;
        }
    }


    2.在Activity 中的oncreate方法中添加
        AppClose appState = (AppClose)this.getApplication();
            appState.addActivity(this);
           // setContentView(R.layout.main);

    3.//设定点击事件
    button.setonclick....(){

    AppClose appState = (AppClose)getApplicationContext();
                     appState.finishAll();
    }

    4.在注册清单文件中
    给application添加属性  android:name=".AppClose"

  • 相关阅读:
    [转]男人25岁之前应该懂得的21个道理
    family album U.S.A 05
    Humour
    Pretty Boy
    [转]男人本色.女人风韵
    电话英语
    搞不懂的女人
    family album U.S.A 03
    [转]The flame of love(爱的火焰)
    四季花开!
  • 原文地址:https://www.cnblogs.com/taogev5/p/5716202.html
Copyright © 2011-2022 走看看