Skip to content

Commit 67dae0c

Browse files
authored
Merge pull request #650 from android/tj/manual-sync
Initialize sync manually
2 parents f3faec8 + 489502b commit 67dae0c

File tree

5 files changed

+5
-48
lines changed

5 files changed

+5
-48
lines changed

gradle/libs.versions.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ androidx-metrics = { group = "androidx.metrics", name = "metrics-performance", v
8787
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "androidxNavigation" }
8888
androidx-navigation-testing = { group = "androidx.navigation", name = "navigation-testing", version.ref = "androidxNavigation" }
8989
androidx-profileinstaller = { group = "androidx.profileinstaller", name = "profileinstaller", version.ref = "androidxProfileinstaller" }
90-
androidx-startup = { group = "androidx.startup", name = "startup-runtime", version.ref = "androidxStartup" }
9190
androidx-test-core = { group = "androidx.test", name = "core", version.ref = "androidxTestCore" }
9291
androidx-test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidxEspresso" }
9392
androidx-test-ext = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "androidxTestExt" }

sync/work/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ dependencies {
3333
implementation(project(":core:datastore"))
3434
implementation(project(":core:model"))
3535
implementation(libs.androidx.lifecycle.livedata.ktx)
36-
implementation(libs.androidx.startup)
3736
implementation(libs.androidx.tracing.ktx)
3837
implementation(libs.androidx.work.ktx)
3938
implementation(libs.firebase.cloud.messaging)

sync/work/src/demo/AndroidManifest.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@
1818
xmlns:tools="http://schemas.android.com/tools">
1919

2020
<application>
21-
<provider
22-
android:name="androidx.startup.InitializationProvider"
23-
android:authorities="${applicationId}.androidx-startup"
24-
android:exported="false"
25-
tools:node="merge">
26-
<!-- TODO: b/2173216 Disable auto sync startup till it works well with instrumented tests -->
27-
<meta-data
28-
android:name="com.google.samples.apps.nowinandroid.sync.initializers.SyncInitializer"
29-
android:value="androidx.startup"
30-
tools:node="remove" />
31-
</provider>
3221
<service
3322
android:name=".services.SyncNotificationsService"
3423
android:exported="false"

sync/work/src/main/AndroidManifest.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@
1818
xmlns:tools="http://schemas.android.com/tools">
1919

2020
<application>
21-
<provider
22-
android:name="androidx.startup.InitializationProvider"
23-
android:authorities="${applicationId}.androidx-startup"
24-
android:exported="false"
25-
tools:node="merge">
26-
<!-- TODO: b/2173216 Disable auto sync startup till it works well with instrumented tests -->
27-
<meta-data
28-
android:name="com.google.samples.apps.nowinandroid.sync.initializers.SyncInitializer"
29-
android:value="androidx.startup"
30-
tools:node="remove" />
31-
</provider>
3221
<service
3322
android:name=".services.SyncNotificationsService"
3423
android:exported="false">

sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/initializers/SyncInitializer.kt

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,14 @@
1717
package com.google.samples.apps.nowinandroid.sync.initializers
1818

1919
import android.content.Context
20-
import androidx.startup.AppInitializer
21-
import androidx.startup.Initializer
2220
import androidx.work.ExistingWorkPolicy
2321
import androidx.work.WorkManager
24-
import androidx.work.WorkManagerInitializer
2522
import com.google.samples.apps.nowinandroid.sync.workers.SyncWorker
2623

2724
object Sync {
28-
// This method is a workaround to manually initialize the sync process instead of relying on
29-
// automatic initialization with Androidx Startup. It is called from the app module's
30-
// Application.onCreate() and should be only done once.
25+
// This method is initializes sync, the process that keeps the app's data current.
26+
// It is called from the app module's Application.onCreate() and should be only done once.
3127
fun initialize(context: Context) {
32-
AppInitializer.getInstance(context)
33-
.initializeComponent(SyncInitializer::class.java)
34-
}
35-
}
36-
37-
// This name should not be changed otherwise the app may have concurrent sync requests running
38-
internal const val SyncWorkName = "SyncWorkName"
39-
40-
/**
41-
* Registers work to sync the data layer periodically on app startup.
42-
*/
43-
class SyncInitializer : Initializer<Sync> {
44-
override fun create(context: Context): Sync {
4528
WorkManager.getInstance(context).apply {
4629
// Run sync on app startup and ensure only one sync worker runs at any time
4730
enqueueUniqueWork(
@@ -50,10 +33,8 @@ class SyncInitializer : Initializer<Sync> {
5033
SyncWorker.startUpSyncWork(),
5134
)
5235
}
53-
54-
return Sync
5536
}
56-
57-
override fun dependencies(): List<Class<out Initializer<*>>> =
58-
listOf(WorkManagerInitializer::class.java)
5937
}
38+
39+
// This name should not be changed otherwise the app may have concurrent sync requests running
40+
internal const val SyncWorkName = "SyncWorkName"

0 commit comments

Comments
 (0)