android service不被kill的方法

来源:互联网 发布:b超数据看男孩女孩 编辑:程序博客网 时间:2024/04/25 23:22
private ActivityManager activityManager;
activityManager = (ActivityManager) mcontext.getSystemService(Context.ACTIVITY_SERVICE); IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);filter.addAction(Intent.ACTION_SCREEN_ON);registerReceiver(mBatInfoReceiver, filter);
   private final BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {        @Override        public void onReceive(final Context context, final Intent intent) {            final String action = intent.getAction();            if (Intent.ACTION_SCREEN_OFF.equals(action)) {                activityManager.moveTaskToFront(Activity(你的activity)).getTaskId(), 1);            } else if (Intent.ACTION_SCREEN_ON.equals(action)) {//                                (Activity(你的activity)).moveTaskToBack(true);            }        }    };
这些代码添加在service类中。

1 0
原创粉丝点击