Skip to content

Commit

Permalink
Updated PendingIntent logic for using only the same PendingIntent, an…
Browse files Browse the repository at this point in the history
…d update if necessary
  • Loading branch information
Javinator9889 committed Jun 27, 2020
1 parent fd8889a commit 8415134
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Expand Up @@ -19,6 +19,7 @@
package com.javinator9889.handwashingreminder.gms.activity

import android.app.PendingIntent
import android.app.PendingIntent.FLAG_UPDATE_CURRENT
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
Expand Down Expand Up @@ -88,6 +89,7 @@ class ActivityHandler private constructor(private val context: Context) {
fun reload() = with(createSetOfTransitions()) {
transitions.clear()
addTransitions(this, transitions)
Timber.d("Reloading activity recognition - transitions: $transitions")
disableActivityTracker()?.let {
it.addOnCompleteListener {
pendingIntent = createPendingIntent()
Expand Down Expand Up @@ -124,7 +126,12 @@ class ActivityHandler private constructor(private val context: Context) {

private fun createPendingIntent(): PendingIntent =
with(Intent(TRANSITIONS_RECEIVER_ACTION)) {
PendingIntent.getBroadcast(context, ACTIVITY_REQUEST_CODE, this, 0)
PendingIntent.getBroadcast(
context,
ACTIVITY_REQUEST_CODE,
this,
FLAG_UPDATE_CURRENT
)
}

private fun registerActivityReceiver() =
Expand Down
Expand Up @@ -102,7 +102,7 @@ class ActivityReceiver : BroadcastReceiver() {
R.string.activity_notification_vehicle_content
)
else -> throw IllegalArgumentException(
"Activity not recognized"
"Activity not recognized - $detectedActivity"
)
}
var title = context.getText(notificationContent.title)
Expand Down

0 comments on commit 8415134

Please sign in to comment.