Tommy Lee
Tommy Lee

Reputation: 794

Android - How to make app autorun in background daily to fetch data from internet?

I am developing a web crawler using Android. Currently my crawler crawls the web using asynctask every time the app starts, which takes a long time.

I want my app to update its database daily in the background, without needing to launch the MainActivity interface. After doing some research, I found the following classes can help me:

  1. Service
  2. AlarmManager

Can someone shed some light for me, I'm new to Android programming. Thanks

Upvotes: 1

Views: 2484

Answers (2)

Gaurav
Gaurav

Reputation: 76

Below are some ways that you can go about doing job scheduling:

You can schedule it to run every X hours with other params like run when internet comes, battery should be above critical level. Check them out and make a decision according to your requirements.

Upvotes: 1

Sandro Machado
Sandro Machado

Reputation: 10215

You should read this chapter: https://developer.android.com/training/best-background.html

You need an alarm manager to run the service every hour. You also need to receive a broadcast when the device reboots to start the alarm manager...

This can also help you: Alarm Manager Example

Upvotes: 1

Related Questions