[android] Differentiate requestCode for PendingIntent #9198

Closed
RicoElectrico wants to merge 1 commit from mb-PendingIntent-requestCode-fix into master
RicoElectrico commented 2024-09-01 23:14:07 +00:00 (Migrated from github.com)

Fixes a bug when tapping the track recorder notification does not return to Organic Maps if there was a navigation session and its corresponding notification.

Steps to reproduce the issue this PR fixes:

  1. Enable track recording
  2. Start navigation
  3. Exit navigation
  4. Switch OM into background
  5. Tapping the track recording notification will do nothing instead of opening OM
Fixes a bug when tapping the track recorder notification does not return to Organic Maps if there was a navigation session and its corresponding notification. Steps to reproduce the issue this PR fixes: 1. Enable track recording 2. Start navigation 3. Exit navigation 4. Switch OM into background 5. Tapping the track recording notification will do nothing instead of opening OM
rtsisyk reviewed 2024-09-01 23:14:07 +00:00
biodranik (Migrated from github.com) reviewed 2024-09-02 10:52:56 +00:00
biodranik (Migrated from github.com) commented 2024-09-02 10:52:56 +00:00

Thanks! What do these codes/integers mean? Are they specified somewhere else? Do they need some constants?

Another question: what are the steps to reproduce the issue you're fixing? Can you please write them in the PR description (or create an issue)?

Thanks! What do these codes/integers mean? Are they specified somewhere else? Do they need some constants? Another question: what are the steps to reproduce the issue you're fixing? Can you please write them in the PR description (or create an issue)?
RicoElectrico (Migrated from github.com) reviewed 2024-09-02 11:20:30 +00:00
RicoElectrico (Migrated from github.com) commented 2024-09-02 11:20:30 +00:00

I updated the PR description. These numbers are pretty much arbitrary and identify pending intents. In our case the requestCode is not used elsewhere in the app as pending intents are not further manipulated. If they're set to the same number and the target intent is the same, they will be overwritten by each other. This change makes the 3 pending intents take separate identities instead.
If you think that using constants will be more clear, that's a valid concern and I'm going to update the PR.

I updated the PR description. These numbers are pretty much arbitrary and identify pending intents. In our case the requestCode is not used elsewhere in the app as pending intents are not further manipulated. If they're set to the same number and the target intent is the same, they will be overwritten by each other. This change makes the 3 pending intents take separate identities instead. If you think that using constants will be more clear, that's a valid concern and I'm going to update the PR.
biodranik (Migrated from github.com) reviewed 2024-09-02 13:00:34 +00:00
biodranik (Migrated from github.com) commented 2024-09-02 13:00:34 +00:00

Should they each time be unique/random? Or the same for the same use-case (to override only itself)? If the latter, then something like PendingIntentId.DownloadNotification would be clearer.

Should they each time be unique/random? Or the same for the same use-case (to override only itself)? If the latter, then something like PendingIntentId.DownloadNotification would be clearer.
biodranik (Migrated from github.com) reviewed 2024-09-02 22:13:21 +00:00
@ -46,6 +46,7 @@ public class NavigationService extends Service implements LocationListener
{
private static final String TAG = NavigationService.class.getSimpleName();
private static final String STOP_NAVIGATION = "STOP_NAVIGATION";
private static final int REQ_CODE_STOP_NAVIGATION = 1;
biodranik (Migrated from github.com) commented 2024-09-02 22:13:21 +00:00

Should these codes be unique compared to MwmActivity ones? If yes, then it would be safer to keep all such codes in a single file/place, to avoid accidentally reusing the same code for different notifications. WDYT?

Should these codes be unique compared to MwmActivity ones? If yes, then it would be safer to keep all such codes in a single file/place, to avoid accidentally reusing the same code for different notifications. WDYT?
RicoElectrico (Migrated from github.com) reviewed 2024-09-02 22:29:33 +00:00
@ -46,6 +46,7 @@ public class NavigationService extends Service implements LocationListener
{
private static final String TAG = NavigationService.class.getSimpleName();
private static final String STOP_NAVIGATION = "STOP_NAVIGATION";
private static final int REQ_CODE_STOP_NAVIGATION = 1;
RicoElectrico (Migrated from github.com) commented 2024-09-02 22:29:33 +00:00

I found another cleaner way to deal with the issue. As all the pending intents do the same thing, one can use FLAG_UPDATE_CURRENT which will not cancel the pending intent from the previous invocation. As a result all the services hold a reference to the same pending intent doing the desired thing i.e. opening OM in the foreground.
I think we need an Android expert to comment on what is considered best practice.

I found another cleaner way to deal with the issue. As all the pending intents do the same thing, one can use FLAG_UPDATE_CURRENT which will not cancel the pending intent from the previous invocation. As a result all the services hold a reference to the same pending intent doing the desired thing i.e. opening OM in the foreground. I think we need an Android expert to comment on what is considered best practice.
kavikhalique (Migrated from github.com) reviewed 2024-09-05 22:09:00 +00:00
@ -46,6 +46,7 @@ public class NavigationService extends Service implements LocationListener
{
private static final String TAG = NavigationService.class.getSimpleName();
private static final String STOP_NAVIGATION = "STOP_NAVIGATION";
private static final int REQ_CODE_STOP_NAVIGATION = 1;
kavikhalique (Migrated from github.com) commented 2024-09-05 22:09:00 +00:00

I will go with FLAG_UPDATE_CURRENT

As android suggests to use FLAG_CANCEL_CURRENT only if you want to invalidate all other instances of pending intent by any service but here our logic is not to invalidate previous instances and also using it will remove the problem of similar pending intent creation by mistake.

I will go with FLAG_UPDATE_CURRENT As android suggests to use FLAG_CANCEL_CURRENT only if you want to invalidate all other instances of pending intent by any service but here our logic is not to invalidate previous instances and also using it will remove the problem of similar pending intent creation by mistake.
kavikhalique (Migrated from github.com) approved these changes 2024-09-06 17:54:14 +00:00
This repo is archived. You cannot comment on pull requests.
No labels
Accessibility
Accessibility
Address
Address
Android
Android
Android Auto
Android Auto
Android Automotive (AAOS)
Android Automotive (AAOS)
API
API
AppGallery
AppGallery
AppStore
AppStore
Battery and Performance
Battery and Performance
Blocker
Blocker
Bookmarks and Tracks
Bookmarks and Tracks
Borders
Borders
Bug
Bug
Build
Build
CarPlay
CarPlay
Classificator
Classificator
Community
Community
Core
Core
CrashReports
CrashReports
Cycling
Cycling
Desktop
Desktop
DevEx
DevEx
DevOps
DevOps
dev_sandbox
dev_sandbox
Directions
Directions
Documentation
Documentation
Downloader
Downloader
Drape
Drape
Driving
Driving
Duplicate
Duplicate
Editor
Editor
Elevation
Elevation
Enhancement
Enhancement
Epic
Epic
External Map Datasets
External Map Datasets
F-Droid
F-Droid
Fonts
Fonts
Frequently User Reported
Frequently User Reported
Fund
Fund
Generator
Generator
Good first issue
Good first issue
Google Play
Google Play
GPS
GPS
GSoC
GSoC
iCloud
iCloud
Icons
Icons
iOS
iOS
Legal
Legal
Linux Desktop
Linux Desktop
Linux packaging
Linux packaging
Linux Phone
Linux Phone
Mac OS
Mac OS
Map Data
Map Data
Metro
Metro
Navigation
Navigation
Need Feedback
Need Feedback
Night Mode
Night Mode
NLnet 2024-06-281
NLnet 2024-06-281
No Feature Parity
No Feature Parity
Opening Hours
Opening Hours
Outdoors
Outdoors
POI Info
POI Info
Privacy
Privacy
Public Transport
Public Transport
Raw Idea
Raw Idea
Refactoring
Refactoring
Regional
Regional
Regression
Regression
Releases
Releases
RoboTest
RoboTest
Route Planning
Route Planning
Routing
Routing
Ruler
Ruler
Search
Search
Security
Security
Styles
Styles
Tests
Tests
Track Recording
Track Recording
Translations
Translations
TTS
TTS
UI
UI
UX
UX
Walk Navigation
Walk Navigation
Watches
Watches
Web
Web
Wikipedia
Wikipedia
Windows
Windows
Won't fix
Won't fix
World Map
World Map
No milestone
No project
No assignees
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: organicmaps/organicmaps-tmp#9198
No description provided.