0

Android SyncAdapter is not considering static variable values set by main thread. As static variables persist through application, it is expected to share across threads. But SyncAdapter is not considering those values set by main thread and taking default values. Help me in finding out solution for this. I need my static values to be used by SyncAdapter.

1 Answers1

1

Static values persist only while main process lives. Android can stop your process at any time and you are not guaranteed that when your SyncAdapter starts, process will be alive. So, you should use other options for storing of your values for SyncAdapter:

  • pass your values with bundle when you request sync with ContentResolver.requestSync()
  • save values to SharedPreferences and read them from SyncAdapter
  • save values to Sqlite database and query them from SyncAdapter.
lobzik
  • 10,974
  • 1
  • 27
  • 32
  • I would add that accompanied SyncService is usually defined to live in separate process defined in manifest `android:process`. So static variable will not be visible. – mauron85 Apr 23 '18 at 11:01