i am developing sample application, it has a sqlite and mysql databases. if internet connection has data goes to the web server database(mysql database), if haven' t a internet connection data save sqlite database, after reopening application synchronizing with the web server database(mysql database), now i want to synchronizing web server database(mysql database) with out reopening the application, run time of the application should be synchronizing. help me
Asked
Active
Viewed 45 times
0
-
i think static block is helpful for you – anddevmanu Sep 09 '13 at 17:12
-
tell me another way.. – Tharaka Sep 09 '13 at 17:17
1 Answers
1
Use a BroadcastReceiver and declare it in the AndroidManifest
with...
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
You wil also need...
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
...in the manifest.
In the onReceive(...)
method of the BroadcastReceiver
check the Intent
to see what change has occurred - if it has changed to connected, you can start a sync operation.
To perform the sync, use an IntentService which will perform the work on a worker thread and then self-terminate when the work is done.
If you want periodic backups, you should also consider using AlarmManager to create a repeating alarm which can be used to fire the IntentService
at regular intervals. In this case the IntentService
will obviously have to perform an explicit check to see if there is a connection to the Internet available.

Squonk
- 48,735
- 19
- 103
- 135