首页 > 代码库 > Android -- 使用广播监听Home键

Android -- 使用广播监听Home键

//广播监听事件类

public class HomeKeyEventBroadCastReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {
        //do what you want
        System.exit(0);
    }
}

private HomeKeyEventBroadCastReceiver homeKeyEventReceiver;protected void onResume() {
     super.onResume();     //监听Home建
     homeKeyEventReceiver = new HomeKeyEventBroadCastReceiver();
     registerReceiver(homeKeyEventReceiver, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
}

@Override
protected void onStop() {
    unregisterReceiver(homeKeyEventReceiver);
    super.onStop();
}


http://862123204-qq-com.iteye.com/blog/1888532

Android -- 使用广播监听Home键