android service不被kill的方法
2016-07-22 15:54
381 查看
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类中。
相关文章推荐
- android 屏幕保持不锁屏
- android动态屏幕适配(不需要多套图,多布局)
- Android自定义控件实现滑动开关效果
- android6.0系统Healthd深入分析
- 你真的会用Gson吗?Gson使用指南(一)
- Android适配器中字体颜色设置无效解决
- MTK开机时间慢分析
- Android音频焦点
- Android ListView 详解
- Android--选择对话框--AlertDialog
- ListView去除默认的点击效果和分割线
- CollapsingToolbarLayout简单应用
- 最新的Android版本和API Level的对应关系表
- Android开发错误总结
- 【android异步处理】一个关于android异步处理的文章系列
- android Monkey的使用详解
- Android Binder设计与实现 - 设计篇
- 如何学好Android 学习指南
- Android PowerImageView实现,可以播放动画的强大ImageView
- Android多点触控技术