我为广播接收器和服务编写了程序,但我在清单文件中感到困惑,有一些注册服务和接收器的基础工作,有人能给我明确的想法吗?提前致谢。
问问题
4186 次
3 回答
4
服务
当您想在后台做某事时使用它,任何长时间运行的进程都可以使用后台服务完成。
即使应用程序关闭,它也将始终在后台运行
例如,您想在应用程序关闭时播放音乐。在这种情况下,服务将在背景音乐中运行。
广播接收器
当您想在某些事件期间触发某些东西或代码时使用它。例如,事件可以在设备启动上。
通常系统会发送一些信息,如果您愿意,您的应用可以通过注册接收这些信息。当事情发生时,您可以使用 onReceive 方法做您想做的事情。示例是系统将在新短信到达或启动完成时发送 BroadcastReceiver
例如,如果您想在设备启动时执行某些操作,日期和时间更改等。
于 2013-01-04T05:17:03.823 回答
1
服务用于在没有用户交互的情况下执行长时间运行的操作或为其他应用程序提供功能。
A Service needs to be declared in the AndroidManifest.xml via
a <service android:name="yourclasss"> </service> and the implementing class
must extend the Service class or one of its subclasses.
To start Services automatically after the Android system starts you can register
a BroadcastReceiver to the Android android.intent.action.BOOT_COMPLETED system
event. This requires the android.permission.RECEIVE_BOOT_COMPLETED permission.
有关更多详细信息,请查看此http://www.vogella.com/articles/AndroidServices/article.html#pre_broadcastreceiver
于 2013-01-04T05:10:13.810 回答