title: Android: how to have a localbroadcast reciever inside service
body: <p>I have service in which I want to have a localbroadcast receiver. I want to recieve a value from the activity to my services onCreate.</p>
  
  <p>Note: I can get a value from an activity to my service in onStartCommand() using intent. But here I want a value from activity in onCreate of the service.</p>
  
  <p>The following is my service file:</p>
  
  <pre><code>    public class MediaServiceSimha extends Service {
  
          private MediaPlayer player;
          String musicpath;
          private ResponseReceiver receiver;
  
          public MediaServiceSimha() {}
  
          @Override
          public IBinder onBind(Intent intent) {
              return null;
          }
  
          @Override
          public void onDestroy() {
              LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
              localBroadcastManager.unregisterReceiver(receiver);
              super.onDestroy();
          }
  
          @Override
          public boolean onUnbind(Intent intent) {
              return super.onUnbind(intent);
          }
  
          @
          Override
          public int onStartCommand(Intent intent, int flags, int startId) {
              player.start();
              return super.onStartCommand(intent, flags, startId);
          }
  
          @Override
          public void onCreate() {
              super.onCreate();
              IntentFilter broadcastFilter = new IntentFilter("com.example.myintentserviceapp.intent_service.ALL_DONE");
              receiver = new ResponseReceiver();
              LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
              localBroadcastManager.registerReceiver(receiver, broadcastFilter);
          }
  
          public class ResponseReceiver extends BroadcastReceiver {
  
              @Override
              public void onReceive(Context context, Intent intent) {
                  musicpath = intent.getStringExtra("musicpath");
              }
          }
      }
  </code></pre>
  
  <p>The following is my activity file where I want to pass a value called musicpath</p>
  
  <pre><code>public class ServiceTest extends AppCompatActivity {
      Intent intent;
  
      public static final String TEXT_INPUT = "inText";
      //MediaServiceSimha mediaServiceSimha;
  
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          L.m("activity_oncreate_starting");
          setContentView(R.layout.activity_service_test);
          intent= new Intent(this,MediaServiceSimha.class);
  
          startService(intent);
  
          Intent broadcastIntent = new Intent();
          broadcastIntent.setAction("com.example.myintentserviceapp.intent_service.ALL_DONE");
          broadcastIntent.putExtra("musicpath", "/storage/emulated/0/Download/1.mp3");
          LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
          localBroadcastManager.sendBroadcast(broadcastIntent)
      }
  
  
  }
  </code></pre>
  
  <p>After running, it says musicpath value is null.</p>
  
  <p>How to do it?</p>