Boarded departure service now restarts with intent info (so the notification doesn't randomly "freeze")
This commit is contained in:
parent
601d8516e6
commit
0c51fe904d
@ -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<Departure> {
|
||||
}
|
||||
|
||||
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<Departure> {
|
||||
|
||||
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);
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user