# Nav | Svid | Type | Status | MessageId | Sub-messageId | Data(Bytes) | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Nav | 22 | 769 | 1 | 5 | 1 | 8 | 43 | 109 | 105 | -31 | -32 | 75 | 89 | -100 | 35 | -112 |
Nav | 13 | 769 | 1 | 5 | 1 | 8 | 43 | 105 | 64 | -45 | -24 | -119 | -18 | 126 | -97 | 72 |
Nav | 12 | 769 | 1 | 5 | 1 | 8 | 43 | 104 | -58 | -72 | -80 | -109 | -31 | 106 | -65 | -64 |
Nav | 22 | 769 | 1 | 5 | 2 | 16 | -85 | 0 | -124 | -112 | 8 | 5 | -61 | 9 | -67 | -56 |
Nav | 5 | 257 | 1 | 25 | 4 | 34 | -64 | 116 | 36 | 37 | 121 | -84 | 120 | 31 | -18 | 111 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.. | |
// New plugins for Hilt | |
apply plugin: 'kotlin-kapt' | |
apply plugin: 'dagger.hilt.android.plugin' | |
... | |
dependencies { | |
... | |
// To observe the flow within the Service based on the lifecycle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AndroidEntryPoint | |
class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener { | |
... | |
// Data store from which to receive location updates via Flow, injected via Hilt | |
@Inject | |
lateinit var repository: LocationRepository | |
// Get a reference to the Job from the Flow so we can stop it from UI events | |
private var locationFlow: Job? = null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AndroidEntryPoint | |
class ForegroundOnlyLocationService : LifecycleService() { | |
... | |
// Data store (in this case, the SharedLocationManager) that the service will observe, injected via Hilt | |
@Inject | |
lateinit var repository: LocationRepository | |
// Get a reference to the Job from the Flow so we can stop it from UI events | |
private var locationFlow: Job? = null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LocationRepository @Inject constructor( | |
private val sharedLocationManager: SharedLocationManager | |
) { | |
/** | |
* Observable flow for location updates | |
*/ | |
fun getLocations() = sharedLocationManager.locationFlow() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Configuration for DI on the repository and shared location manager | |
*/ | |
@Module | |
@InstallIn(SingletonComponent::class) | |
object DataModule { | |
@Provides | |
@Singleton | |
fun provideSharedLocationManager( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Required for Hilt dependency injection | |
@HiltAndroidApp | |
class LocationApplication : Application() { | |
// No need to cancel this scope as it'll be torn down with the process - see https://medium.com/androiddevelopers/coroutines-patterns-for-work-that-shouldnt-be-cancelled-e26c40f142ad | |
val applicationScope = GlobalScope | |
} |
NewerOlder