/** * 使用方法:* 1、所有的Activity继承这个baseActivity** 2、要退出时,调用this.clossAllActivity()**/
 

   
package com.abc.util;import android.app.Activity;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;/** * function:关闭所有的Activity *  * 基类的Activity,每个Activity都继承自这个基类Activity, * 在这个基类Activity中写个广播,当程序退出的时候,发送关闭Activity的广播。 * */public class BaseActivity extends Activity{public static final String ACTION_CLOSS_ACTIVITY = "com.abc.BaseActivity.finish";private BroadcastReceiver broadcastReceiver = new BroadcastReceiver(){@Overridepublic void onReceive(Context context, Intent intent) {// 结束窗口BaseActivity.this.finish();}};@Override//--activity真正在前台运行中protected void onResume() {super.onResume();// 在当前的activity中注册广播 IntentFilter filter = new IntentFilter();filter.addAction(ACTION_CLOSS_ACTIVITY);this.registerReceiver(broadcastReceiver, filter);}//Activity has leaked IntentReceiver  that was originally registered here. //Are you missing a call to unregisterReceiver()?//注册了广播接收器后要在销毁时取消注册,否则会出错。@Overrideprotected void onDestroy() {this.unregisterReceiver(broadcastReceiver);super.onDestroy();}public void closeAllActivity() {// 发送广播,关闭所有activityIntent intent = new Intent();intent.setAction(ACTION_CLOSS_ACTIVITY);sendBroadcast(intent);//--发送当前的意图}}


 

   
                                                                                               

更多相关文章

  1. android中的handler的使用方法
  2. Android触控屏幕Gesture(GestureDetector和SimpleOnGestureListe
  3. Android之TabHost的几种使用方法
  4. Android-Intent的使用方法详解
  5. Android pm命令使用方法
  6. android投屏和媒体共享相关 && audio focus机制相关 && AudioTra
  7. Android Studio SVN 使用方法
  8. Ashmem(Android共享内存)使用方法和原理
  9. Android GridView的使用方法

随机推荐

  1. Python十题(第2课)
  2. 流畅python学习笔记:第十二章:子类化内置类
  3. Pandas concat:ValueError:传递值的形状为b
  4. Python中类的使用(5私有属性)
  5. 求助:Python是否可以用一行代码来同时给变
  6. 【Python】torrentParser1.04 增加获得磁
  7. Python常用模块-摘要算法(hashlib)
  8. python魔法方法、构造函数、序列与映射、
  9. pycharm + python36 + opencv + opencv_c
  10. 用户输入从.csv文件生成新列表?