New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[android] Implements exit button in navigation notification #7953
base: master
Are you sure you want to change the base?
[android] Implements exit button in navigation notification #7953
Conversation
Signed-off-by: kavikhalique <kavikhalique3@gmail.com> Implements Exit button in navigation notification Signed-off-by: kavikhalique <kavikhalique3@gmail.com> Implements Exit button in navigation notification 2 Signed-off-by: kavikhalique <kavikhalique3@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
final Intent exitIntent = new Intent(context, NavigationService.class); | ||
exitIntent.setAction(STOP_NAVIGATION); | ||
final PendingIntent exitPendingIntent = PendingIntent.getService(context, 0, exitIntent, | ||
PendingIntent.FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reasoning for selecting these two flags for intent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FLAG_UPDATE_CURRENT insures that there should exist only one pending intent doing same task at any moment. If there is already an existing pendingIntent which is doing same task then rather than creating new pendingIntent it updates the previous one with new one.
Whereas FLAG_IMMUTABLE is used for, if by any reason pendingIntent is cant be overwritten then it creates new one.
android/app/src/main/java/app/organicmaps/routing/NavigationService.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Alexander Borsuk <170263+biodranik@users.noreply.github.com> Signed-off-by: kavi khalique <120750626+kavikhalique@users.noreply.github.com>
Tried it out and found an issue:
Result: |
Thanks, I missed that. Will correct it soon. |
You can use same method used on stop button in navigation bottom bar |
Yes sir, but the issue is that there is a container class which contains all the methods and in background it becomes null because it has been defined inside mwmActivity.java class. I was thinking to create a shared preference variable which will be set to true if notification will be exited from background and then whenever activity will resume in foreground it will check the value of shared preference and if it will be true it will trigger the stop button method of navigationController. |
Is it possible to call the same methods that are called by pressing the stop button in the nav panel? |
Yes sir, I am calling the same method but whenever that method is triggered from background of navigation activity it does not updates the map activity to default. Trying to figure it out where things are actually changing. |
Signed-off-by: kavikhalique <kavikhalique3@gmail.com>
…t-button-navigation
Fixed the issue of UI updation after exiting navigation from background of app. What i did - Used Shared preferences to check if app is in background or foreground and accordingly called methods after coming in foreground which were not available when app was in background. Please review it - @Jean-BaptisteC @RedAuburn |
Please sir review my changes and if there is any changes required please inform me. @rtsisyk @biodranik |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the only/cleanest way to fix the issue?
I have gone through OSMAnd's code base for exit button they have created a broadcast receiver and they have a separate class which determines the mode of application and then according to foreground or background mode actions are taken. Since I didn't found any such class to determine the mode of app i used shared preference. I feel better and cleaner ways exist. |
Sir please review it and if there is any suggestions please disscuss so that i can correct it @rtsisyk |
I will take a look. Sorry for the delay!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution, and sorry for the delay with the code review. 🙏
Could you please evaluate the idea of routing STOP_NAVIGATION intent via MwmActivity to eliminate the need of using IS_CANCELLED_FROM_BACKGROUND
flag in Preferences (see a comment inline)? I think it would make the code even much simpler.
@@ -2186,4 +2190,19 @@ public void onTrimMemory(int level) | |||
if (level >= TRIM_MEMORY_RUNNING_LOW) | |||
Framework.nativeMemoryWarning(); | |||
} | |||
|
|||
public void onCancelledFromBackground(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about routing STOP_NAVIGATION
intent via MwmActiviy instead of sending it directly to NavigationService? The intent will appear in MwmActiviy.onNewIntent(), where it will be possible to stop the NavigationService and restore the UI of MwmActivity. It should work regardless of the current foreground/background state of MwmActivity. This approach eliminates the need for IS_CANCELLED_FROM_BACKGROUND
flag stored in Preferences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the guidance, idea seems perfect will work upon it.
I dont know why this idea didn't strike in my mind. Your idea is much better and clean will modify the code accordingly and will update you ASAP. The only doubt i have is, if we will send intent to activity class it will open up the activity in foreground (means it will open the app) I will check this out once and then will update you |
I have tried that but the issue is with UX. If we will route STOP_NAVIGATION through mwmActivity it opens the app in foreground. But if the navigation is cancelled from background it should not bring the app in foreground. It should just close the notification. |
Fixes #7492
Implements Exit button in navigation notification
Use Case -
1 - If user clicks on exit navigation in background of app it simply stops navigation and closes the notification
2 - If user clicks the button while app is in foreground it works similar to pressing the stop button in bottom navigation of navigation screen
What I changed -
I added one button in notification and attached a pending intent with the button. Pending intent runs once the exit button gets clicked. It triggers cancel() method inside RoutingController.java class which basically stops the navigation which is going on. Then it triggers another method stopself() which closes the notification.
Screenshots-
Sample Video -
fix4.mp4