Skip to content

Commit

Permalink
refactor: Add custom work manager initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
PolinaPolupan committed Nov 23, 2024
1 parent 1f23de0 commit f381646
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
android:supportsRtl="true"
android:theme="@style/Theme.MyMusic"
tools:targetApi="31">
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">

<meta-data
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup"
tools:node="remove" />

</provider>
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
22 changes: 20 additions & 2 deletions app/src/main/java/com/example/mymusic/MyMusicApplication.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
package com.example.mymusic

import android.app.Application
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import com.example.mymusic.sync.Sync
import dagger.hilt.EntryPoint
import dagger.hilt.EntryPoints
import dagger.hilt.InstallIn
import dagger.hilt.android.HiltAndroidApp
import dagger.hilt.components.SingletonComponent

@HiltAndroidApp
class MyMusicApplication : Application() {
class MyMusicApplication : Application(), Configuration.Provider {

@EntryPoint
@InstallIn(SingletonComponent::class)
interface HiltWorkerFactoryEntryPoint {
fun workerFactory(): HiltWorkerFactory
}

override val workManagerConfiguration: Configuration =
Configuration.Builder()
.setWorkerFactory(EntryPoints.get(this, HiltWorkerFactoryEntryPoint::class.java).workerFactory())
.setMinimumLoggingLevel(android.util.Log.INFO)
.build()

override fun onCreate() {
super.onCreate()
// Initialize Sync; the system responsible for keeping data in the app up to date.
com.example.mymusic.sync.Sync.initialize(context = this)
Sync.initialize(context = this)
}
}

0 comments on commit f381646

Please sign in to comment.