I am making a media player ,who can run in background. i have to send a string uri in this service. but i cant send the uri value from my activity through bundle.Services cl
If you are trying to send a string or String-array from one Activity to another this can be done in the Intent.
In ClassA:
Intent intent = new Intent(this, ClassB);
tring[] myStrings = new String[] {"test", "test2"};
intent.putExtra("strings", myStrings);
startActivity(intent);
In ClassB:
public void onCreate() {
Intent intent = getIntent();
String[] myStrings = intent.getStringArrayExtra("strings");
}
You should use IntentService http://developer.android.com/reference/android/app/IntentService.html.
Implement onHandleIntent(Intent intent)
which will be called each time you start service with the startService(intent)
. You can pass your data to service through this intent.