[ACCEPTED]-Android: start service with parameter-android-activity
Accepted answer
Intent serviceIntent = new Intent(this,ListenLocationService.class);
serviceIntent.putExtra("From", "Main");
startService(serviceIntent);
//and get the parameter in onStart method of your service class
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Bundle extras = intent.getExtras();
if(extras == null) {
Log.d("Service","null");
} else {
Log.d("Service","not null");
String from = (String) extras.get("From");
if(from.equalsIgnoreCase("Main"))
StartListenLocation();
}
}
0
Step #1: Delete your BroadcastReceiver
implementation.
Step 2 #2: Examine the Intent
your service gets in onStartCommand()
and 1 look at the action via getAction()
.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.