В моем приложении медиапроигрывателя я передаю выбранный URL-адрес своему классу обслуживания, например, из списка.
Resources res = getResources();
String[] links = res.getStringArray(R.array.links);
String url = links[position];
if (playing) {
Intent i = new Intent(MainActivity.this, MpService.class);
stopService(i);
}
playing = true;
Intent start = new Intent(MainActivity.this, MpService.class);
start.putExtra("media", url);
startService(start);
Но на моей кнопке переключения воспроизведения я перезапускаю службу, где мне нужно сохранить тот же URL, который был выбран ранее.
Вот функция toogle:
private void togglePlayPause() {
if (playing) {
playing = false;
nowplaying.setText("Offline");
mPlayerControl.setImageResource(R.drawable.ic_play_circle_filled);
Intent i = new Intent(MainActivity.this, MpService.class);
stopService(i);
} else if (!playing){
playing = true;
Intent i = new Intent(MainActivity.this, MpService.class);
i.putExtra("media",//here is what i'm not getting);
startService(i);
nowplaying.setText("Now Playing");
mPlayerControl.setImageResource(R.drawable.ic_pause_circle_filled);
}
}
Пожалуйста, помогите, как этого добиться? Это мое первое приложение, и это очень запутанно.