我们可以从广播接收器启动用户定义的服务吗?

时间:2012-11-24 14:03:39

标签: android android-intent broadcastreceiver android-service android-2.2-froyo

我正在Android中开发移动设备和平板电脑的应用程序。 我正在使用Android 2.2

在广播接收器中,我们可以放一些简单的过程(小过程/小型运行模块代码片段)。它不适合长时间运行的过程/长时间运行的模块,如 gps位置捕获等。

我们可以从广播接收器启动服务(用户定义的服务 - 而不是Android服务)吗?

1 个答案:

答案 0 :(得分:1)

是的,您可以从BroadcastReceiver启动服务。实际上您需要Context才能启动Service。例如:

@Override
public void onReceive(Context context, Intent intent) {

    Intent intent = new Intent(context, YourService.class);
    context.startService(intent);
}