diff --git a/src/com/dougkeen/bart/model/Departure.java b/src/com/dougkeen/bart/model/Departure.java index c40582f..7698aad 100644 --- a/src/com/dougkeen/bart/model/Departure.java +++ b/src/com/dougkeen/bart/model/Departure.java @@ -19,6 +19,7 @@ import android.util.Log; import com.dougkeen.bart.BartRunnerApplication; import com.dougkeen.bart.R; +import com.dougkeen.bart.activities.ViewDeparturesActivity; import com.dougkeen.bart.services.BoardedDepartureService; import com.dougkeen.util.Observable; @@ -533,8 +534,10 @@ public class Departure implements Parcelable, Comparable { } private PendingIntent getAlarmIntent(Context context) { - return PendingIntent.getBroadcast(context, 0, new Intent( - Constants.ACTION_ALARM, getStationPair().getUri()), + Intent intent = new Intent(context, ViewDeparturesActivity.class); + intent.putExtra(Constants.STATION_PAIR_EXTRA, getStationPair()); + intent.setAction(Constants.ACTION_ALARM); + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } @@ -579,8 +582,10 @@ public class Departure implements Parcelable, Comparable { private PendingIntent getNotificationIntent(Context context) { if (notificationIntent == null) { - Intent targetIntent = new Intent(Intent.ACTION_VIEW, - getStationPair().getUri()); + Intent targetIntent = new Intent(context, + ViewDeparturesActivity.class); + targetIntent.putExtra(Constants.STATION_PAIR_EXTRA, + getStationPair()); targetIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent = PendingIntent.getActivity(context, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT); diff --git a/src/com/dougkeen/bart/receivers/AlarmBroadcastReceiver.java b/src/com/dougkeen/bart/receivers/AlarmBroadcastReceiver.java index 4fb6826..f2f8961 100644 --- a/src/com/dougkeen/bart/receivers/AlarmBroadcastReceiver.java +++ b/src/com/dougkeen/bart/receivers/AlarmBroadcastReceiver.java @@ -5,6 +5,8 @@ import android.content.Context; import android.content.Intent; import com.dougkeen.bart.BartRunnerApplication; +import com.dougkeen.bart.activities.ViewDeparturesActivity; +import com.dougkeen.bart.model.Constants; import com.dougkeen.bart.model.Departure; import com.dougkeen.util.WakeLocker; @@ -24,8 +26,9 @@ public class AlarmBroadcastReceiver extends BroadcastReceiver { application.setPlayAlarmRingtone(true); - Intent targetIntent = new Intent(Intent.ACTION_VIEW, boardedDeparture - .getStationPair().getUri()); + Intent targetIntent = new Intent(context, ViewDeparturesActivity.class); + targetIntent.putExtra(Constants.STATION_PAIR_EXTRA, + boardedDeparture.getStationPair()); targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(targetIntent); diff --git a/src/com/dougkeen/bart/services/BoardedDepartureService.java b/src/com/dougkeen/bart/services/BoardedDepartureService.java index 62d3a98..1d0264e 100644 --- a/src/com/dougkeen/bart/services/BoardedDepartureService.java +++ b/src/com/dougkeen/bart/services/BoardedDepartureService.java @@ -109,7 +109,7 @@ public class BoardedDepartureService extends Service implements public int onStartCommand(Intent intent, int flags, int startId) { mHasShutDown = false; onStart(intent, startId); - return START_STICKY; + return START_REDELIVER_INTENT; } @Override @@ -122,10 +122,21 @@ public class BoardedDepartureService extends Service implements } protected void onHandleIntent(Intent intent) { + if (intent == null) + return; + final BartRunnerApplication application = (BartRunnerApplication) getApplication(); - final Departure boardedDeparture = application.getBoardedDeparture(); - if (boardedDeparture == null || intent == null) { + final Departure boardedDeparture; + if (intent.hasExtra("departure")) { + boardedDeparture = intent.getExtras().getParcelable("departure"); + } else { + boardedDeparture = application.getBoardedDeparture(); + } + if (boardedDeparture == null) { // Nothing to notify about + if (mNotificationManager != null) { + mNotificationManager.cancel(DEPARTURE_NOTIFICATION_ID); + } return; } if (intent.getBooleanExtra("cancelNotifications", false)