-
Notifications
You must be signed in to change notification settings - Fork 42
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
base: main
Are you sure you want to change the base?
NAVAND-1307 example running activity in the background #184
Conversation
* You can disable built-in foreground service by calling `MapboxNavigation.startTripSession(false)` | ||
* and implement notification on your own. | ||
*/ | ||
class BackgroundService : Service(), LifecycleOwner { |
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.
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.
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.
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
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.
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.
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.
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() |
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.
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() { |
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.
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?
This example demonstrates how to keep active guidance session running when activity is destroyed.
background-demo.mp4
Known issues
MapboxNavigation
won't be destroyed asBackgroundService
isn't stopped.