Android中,service的开启,默认是绑定activity的,是activity级的。
如果要实现当退出程序后,保持Service的运行,那么需要把service设置成为system级的,设置方法: 在AndroidManifest.xml中注册service时,加上属性android:process,如:
android:name = "com.jansun.pushnotification.PushNotificationService" android:enabled = "true" android:process = "system" /> 另外,还要在启动service时,加入FLAG_ACTIVITY_NEW_TASK标签,如: public static void actionStart ( Context ctx ) { //System.out.println("---- Notification service started!"); Intent i = new Intent(ctx, PushNotificationService .class); i.setAction(ACTION_START); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startService(i); }
至此,当你退出程序后,service还在系统后台正常运行,目标达成。
- android设置主题和自定义主题的方法
- Android(安卓)Studio 设置背景色
- Android(安卓)使用SVG
- Android应用开发——TextView控件属性列表
- android通过adb设置以太网共享
- Android:设置圆形头像,Android截取圆形图片
- 【安卓学习笔记】Android(安卓)Studio第9课——进度条ProgressBa
- Android(安卓)ListView 滑动背景为黑色的解决办法[转]
- Mac 下设置android NDK的环境
随机推荐
-
如果Imageview与Linearlayout有叠加且可
-
Android的SDK与ADT不匹配问题
-
android studio 报Error:failed to find
-
环境变量ANDROID_SDK_HOME的作用
-
android控件之ImageButton android:scale
-
android布局居中
-
android:各种访问权限Permission
-
android消息处理机制学习(一)-Handler,Mess
-
android 二 BMI 小例子
-
Android 3.0 r1 API中文文档(107) —— A