KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
To start my service from an Activiy I use startService(MyService.class) . This works great, but in a special case the service should be started differently. I want to pass some parameters to the service start. I tried the following in my Activity: Intent startMyService= new Intent(); startMyService.setClass(this,LocalService.class); startMyService.setAction("controller"); startMyService.putExtra(Constants.START_SERVICE_CASE2, true); startService(startMyService); In my Service I use: public class MyIntentReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals("controller")) { // Intent was received } } } The IntentReceiver is registered in onCreate() like this: IntentFilter mControllerIntent = new IntentFilter("controller"); MyIntentReceiver mIntentReceiver= new MyIntentReceiver(); registerReceiver(mIntentReceiver, mControllerIntent); With this solution the service starts but the intent is not received. How can I start a Service and pass my parameters? Thanks for your help!
Tags (comma-separated)
Save Edits
Cancel