Don't autoconnect to service if it was explicity stopped within the application

This commit is contained in:
Christopher Eby 2010-03-12 23:42:26 -06:00
parent 93d59aca7a
commit 7e05f88c4a
4 changed files with 23 additions and 4 deletions

View File

@ -183,7 +183,7 @@ public class NowPlayingActivity extends PlaybackServiceActivity implements View.
{
super.onStart();
bindPlaybackService();
bindPlaybackService(false);
IntentFilter filter = new IntentFilter();
filter.addAction(PlaybackService.EVENT_SONG_CHANGED);
@ -371,7 +371,7 @@ public class NowPlayingActivity extends PlaybackServiceActivity implements View.
updateProgress();
}
} else if (view == mReconnectButton) {
bindPlaybackService();
bindPlaybackService(true);
} else {
try {
if (view == mNextButton)

View File

@ -430,6 +430,10 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(mCallListener, PhoneStateListener.LISTEN_CALL_STATE);
SharedPreferences.Editor editor = mSettings.edit();
editor.putBoolean("explicit_stop", false);
editor.commit();
Looper.loop();
}

View File

@ -23,7 +23,9 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.view.KeyEvent;
public class PlaybackServiceActivity extends Activity implements ServiceConnection {
@ -45,8 +47,16 @@ public class PlaybackServiceActivity extends Activity implements ServiceConnecti
return handleKeyLongPress(this, keyCode);
}
protected void bindPlaybackService()
protected void bindPlaybackService(boolean force)
{
if (!force) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.getBoolean("explicit_stop", false)) {
setService(null);
return;
}
}
Intent intent = new Intent(this, PlaybackService.class);
startService(intent);
bindService(intent, this, Context.BIND_AUTO_CREATE);
@ -54,6 +64,11 @@ public class PlaybackServiceActivity extends Activity implements ServiceConnecti
protected static void stopPlaybackService(Activity activity)
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("explicit_stop", true);
editor.commit();
activity.stopService(new Intent(activity, PlaybackService.class));
}

View File

@ -68,7 +68,7 @@ public class RemoteActivity extends PlaybackServiceActivity implements View.OnCl
{
super.onResume();
bindPlaybackService();
bindPlaybackService(true);
registerReceiver(mReceiver, new IntentFilter(PlaybackService.EVENT_STATE_CHANGED));
}