Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue in Syncing using SyncAdapter in Marshmallow and above version

Core logic : Maintaining posted article in local DB. Syncing the article when device getting the network access.

Classes used:

  • Model class for article.
  • AccountManager to handle the Account.
  • SyncService class registered in AndoidManifest with meta-data android:name="android.content.SyncAdapter" android:resource="@xml/syncadapter"
  • SyncAdapter class extends AbstractThreadedSyncAdapter which is used by SyncSevice.
  • ArticleProvider extends ContentProvider class which manages the article data in ContentProvider.
  • syncadapter.xml which contain a valid ContentAuthority .

The app is working as expected upto Lollipop version. (i.e:) It takes Article data from the content provider and post to Server when network connectivity is available.

The issue occur from Marshmallow version, The requestSync() is not triggering onPerformSync(). So Syncing not occurs. Provide suggestion in this case.

like image 853
Sackurise Avatar asked Jan 20 '18 10:01

Sackurise


1 Answers

The issue occur from Marshmallow version, The requestSync() is not triggering onPerformSync(). So Syncing not occurs. Provide suggestion in this case.

@Sackurise Android 6.0 M implemented Doze and App Standby modes. This was supposed to be a real cool thing for power saving management but it wasn't. Lots of developers are having the same issue as you. Their app background services/process do not work as they should and the problem is this new feature in Android M.

Although Google says that adding your app to a special whitelist could solve the problem (only when it's needed or your app could be banned from google play store, please, look at https://developer.android.com/training/monitoring-device-state/doze-standby.html), there is a post in Google Code that refers to the whole issue and even a Google employee has admited that this whitelist is not helping the apps that rely on background work (network access, getting sensors data....)

I will leave the link of that post here https://code.google.com/archive/p/android-developer-preview/issues/2225

This only happens in Android M, since I'm testing my own app in Android Nougat and it works as it is suppossed to work (Nougat has Doze and App Standby features aswell but they were improved a lot).

I encourage you to keep trying to find a solution to this problem, and if you have success on it, please share!

like image 104
Jose Jet Avatar answered Nov 18 '22 11:11

Jose Jet