静态注册broadcastreceiver(就是说注册到manifest文件里),在onReceive方法里启动service即可。
解决方案 »
- 自己开发了一款手机控制电脑的软件,诚邀大家捧捧场呀!MobCtrl万能遥控
- android网络编程问题
- 为什么我给ImageSwitcher注册了监听事件,当我点击该图片的时候为什么模拟器说程序失败,强制退出?
- android调用SO串口read出错
- 如何将音频记录成ogg文件格式啊?
- 为什么我TabHost的setIndicator设置了图片,但是我的应用显示却显示不出来呢
- android源码编译错误 :源码编译AllJoynObj.o的问题
- 求救啊,通过http协议获得了学校网站的html文件,怎样通过SAX把我想要的信息解析出来
- 游戏中大量的图片,导致崩溃
- airtest poco
- WebView加载远端js调本地java程序
- HTTP POST协议 输出流不阻塞是什么情况
http://blog.csdn.net/weihan1314/article/details/7964748
静态广播,如果进程挂了,一样会不到,我测试过。比如在设置里强行停止,就是杀掉了进程,静态广播收不到的。
另外service也不是杀不死的啊,系统好像也会回收servcie。
/**
* Have the system perform a force stop of everything associated with
* the given application package. All processes that share its uid
* will be killed, all services it has running stopped, all activities
* removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
* broadcast will be sent, so that any of its registered alarms can
* be stopped, notifications removed, etc.
*
* <p>You must hold the permission
* {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
* call this method.
*
* @param packageName The name of the package to be stopped.
*
* @hide This is not available to third party applications due to
* it allowing them to break other applications by stopping their
* services, removing their alarms, etc.
*/
2、强制停止后,我再启动demo,为什么进程没起来呢?是不是所有运行的进程都可以在手机的设置里查看?这个估计你要检查下,应该是能再运行起来的补充一个小问题:很多人说service一般不会被回收,但我发现我的servcie经常被回收,而且我的手机是魅族MX2,配置比较高的,资源不足应该不会吧?提高你的service优先级,减少被回收几率
public final void startForeground (int id, Notification notification)Make this service run in the foreground, supplying the ongoing notification to be shown to the user while in this state. By default services are background, meaning that if the system needs to kill them to reclaim more memory (such as to display a large page in a web browser), they can be killed without too much harm. You can set this flag if killing your service would be disruptive to the user, such as if your service is performing background music playback, so the user would notice if their music stopped playing.
多谢大牛。但第2条,我启动demo,进程却没起来,这个应该跟我没有关系啊,这个是系统的事。