2

I need to sync data with my app and server as soon as possible.

If my app is open and the user has an internet connection, this is easy.

In my current implementation, if the user has no internet, interacts with my app, and then closes it, the app and server do not sync until the app is re-opened.

Is there a way to sync data with my app and server when the user has an internet connection but has not opened the app? links are appreciated!

salih kallai
  • 879
  • 2
  • 13
  • 34
Daiwik Daarun
  • 3,804
  • 7
  • 33
  • 60
  • Have a look at the [Service](http://developer.android.com/guide/components/services.html) class. – Naveed Mar 10 '16 at 19:07
  • you can use the broadcast receiver to sync data to server, when internet connect broadcast will fire, then you code to sync data. BroadCastReceiver should be in menifest defined.. – Ramesh Kumar Mar 30 '16 at 09:47

3 Answers3

4

You can use GCM Network Manager to carry off network related tasks in background. You can implement both periodic and one time tasks using this. This API serves exactly what you want.

Miftakhul Arzak
  • 1,166
  • 1
  • 12
  • 31
Rohit Arya
  • 6,751
  • 1
  • 26
  • 40
2

A few things you should look at:

  1. Services - Running processes in the background http://developer.android.com/guide/components/services.html

  2. Push Notifications - Receiving data from the server https://developers.google.com/cloud-messaging/

  3. Broadcast Receivers (Especially the bootup) so that you can start your service right after the device boots up Android BroadcastReceiver on startup - keep running when Activity is in Background

Community
  • 1
  • 1
swbandit
  • 1,986
  • 1
  • 26
  • 37
1

Checkout android SyncAdapter. Would be best in your case.

It can trigger based on

  1. Time Schedule.
  2. On Gcm message Receive.
  3. On General Call from anywhere within application.
UMESH0492
  • 1,701
  • 18
  • 31