Skip to content
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

NAVAND-1307 example running activity in the background #184

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

VysotskiVadim
Copy link
Contributor

@VysotskiVadim VysotskiVadim commented Apr 7, 2023

This example demonstrates how to keep active guidance session running when activity is destroyed.

background-demo.mp4

Known issues

  • if navigation is stopped via action from push notification, MapboxNavigation won't be destroyed as BackgroundService isn't stopped.

@VysotskiVadim VysotskiVadim requested a review from a team as a code owner April 7, 2023 12:05
* You can disable built-in foreground service by calling `MapboxNavigation.startTripSession(false)`
* and implement notification on your own.
*/
class BackgroundService : Service(), LifecycleOwner {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is custom background service better than our own foreground service?
Also, how is MapboxNavigationApp going to know about this service? I don't see it being notified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is custom background service better than our own foreground service?

Built-in navigation foreground service doesn't prevent MapboxNavigationApp from being destroyed when user leaves activity.

Also, how is MapboxNavigationApp going to know about this service? I don't see it being notified.

Under the hood, requireMapboxNavigation creates MapboxNavigation via MapboxNavigationApp using current object lifecycle

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be a foreground service? Since Nav SDK already has one, I think this can be a simple object, which implements LifecycleOwner and has start and stop functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under the hood, requireMapboxNavigation creates MapboxNavigation via MapboxNavigationApp using current object lifecycle

Ah, the important part here is that inside this service we create mapboxNavigation once again, right? We still use the old instance, but by creating it here we attach this service, and MapboxNavigationApp does not destroy MapboxNavigation while the service is alive?


// initialize view interactions
binding.stop.setOnClickListener {
clearRouteAndStopNavigation()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to stop navigation they still have to return to the activity, right?
Are we not considering the case of stopping navigation from our notification because it behaves strangely?

* - Press the "Stop" button to finish the session. If you leave activity during free drive session,
* MapboxNavigation will be destroyed.
*/
class BackgroundExampleActivity : AppCompatActivity() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of boiler-plate code here. It makes it harder to track which parts are important for background. Can we remove all the unnecessary code from here and just keep the bare minimum?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants