Android - How to download data in the background at a specified time

I apologize for the fact that I did not have any code to publish, mainly because I can’t understand for life how I need to do what I need to do.

Basically, at certain intervals during the day (for example, 5 PM), I want my application to download some data from my server and store it on the device. This is done both to reduce the load on my server, and when loading data every time the application is launched, as well as to reduce the download time for the user, so that when they come to use the application, the latest data is already on your device.

I have absolutely no idea how to do this. I know how to load data correctly, but now how to load in the background, as I plan. Is it possible?

I do not ask anyone to do this for me, but someone can point me in the right direction.

+7
java android background sync
source share
3 answers

Use AlarmManager

This class provides access to system signaling services. This allows you to plan the launch of the application at some point in the future. When the alarm goes off, the Intent registered for it is broadcast by the system, automatically launching the target application if it is not already running. The registered alarms are saved when the device is asleep (and, if necessary, can activate the device if it is turned off during this time), but will be cleared if it is turned off and rebooted.

Use it to start Service

A service is a component of an application that represents either an application that wants to do longer work without interacting with the user, or providing functionality for use by other applications.

The Demos API includes an example of a signaling service (in the Application section) that:

Demonstrates how you can set an alarm that causes the service to start. This is useful if you want to schedule alarms that trigger lengthy operations, such as receiving the latest emails.

In particular, see AlarmService.java for an example of using AlarmManager to schedule your service that you need to wake up later, and see AlarmService_Service.java for an example of how to respond to this signal. The Demo API AndroidManifest.xml contains the corresponding service and action definitions:

  <service android:name=".app.AlarmService_Service" android:process=":remote" /> <activity android:name=".app.AlarmService" android:label="@string/activity_alarm_service"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.SAMPLE_CODE" /> </intent-filter> </activity> 
+15
source share

Write Service .

Use AlarmManager .

+3
source share

Maybe someone can point me in the right direction.

AlarmManager , Service , AsyncTask , BroadcastReceiver p>

  <receiver android:name=".receiver.BootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> 
0
source share

All Articles