1

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

Tommy Lee
  • 794
  • 2
  • 11
  • 30

2 Answers2

1

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

Community
  • 1
  • 1
Sandro Machado
  • 9,921
  • 4
  • 36
  • 57
  • so do I need to call the service somewhere in the MainActivity? or Android does it automatically from the appmanifest? – Tommy Lee Dec 18 '14 at 18:37
  • You need to start it from the main activity and from the class referenced in the broadcast receiver related to "OnBootComplet" event – Sandro Machado Dec 18 '14 at 18:58
1

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.

Gaurav
  • 76
  • 5