I have a service in android, and I need to pass parameters to it..I have no idea how to do it..
I tried to putExtra but it wasn't an intent...I used constructor but it doesn't work with constructors..
I have a service in android, and I need to pass parameters to it..I have no idea how to do it..
I tried to putExtra but it wasn't an intent...I used constructor but it doesn't work with constructors..
From Activity:
Intent intent = new Intent(this, YourService.class);
intent.putExtra("someKey", someData);
intent.putExtra("anotherKey", anotherData);
startService(intent);
In YourService :
public void onStartCommand(Intent data, int startId, int flags) {
int data1 = data.getExtra("someKey");
int data2 = data.getExtra("anotherKey");
}
Thanks.
public int onStartCommand(Intent intent, int flags, int startId) {
String[] info = intent.getStringArrayExtra("information");
}