如何从一个BroadcastReciever启动两个服务或活动

时间:2015-09-11 13:41:06

标签: android

我正在尝试仅使用一个Broadcastreciver重启设备时启动两项服务。但是只调用一个服务。 我是android的新手,所以需要帮助。

这是我的收件人:

public class FirstReciever extends BroadcastReceiver{
      private static final String TAG8 = "Mytag";

      @Override
      public void onReceive(Context context, Intent intent) {
           if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {    
           Log.i(TAG8, "Restarting App after boot");
           Intent myServiceInent = new Intent(context, FirstReciever.class);
           context.startService(myServiceInent);
           Intent myServiceInent1 = new Intent(context, DbService.class);
           context.startService(myServiceInent1);
           }
     }
}

2 个答案:

答案 0 :(得分:0)

开始使用活动:
startActivity(intent);
启动服务使用:
startService(intent);

答案 1 :(得分:0)

首先看看这个。

Intent myServiceInent = new Intent(context, FirstReciever.class);

           context.startService(myServiceInent);

您已经提供了FirstReciever.class的引用,这应该是一项服务。

如果这不起作用而不是启动单个服务并从第一个服务启动另一个服务......