android - Perform database actions in the background every 10 minutes -


i want perform database actions in background every 10 minutes. best method?

maybe:

  • threads: how?
  • services: very complicated?
  • asynctasks: too long period

my current approach:

countdowntimer cleardbscountdowntimer = new countdowntimer(600000, 600000) {     @override     public void onfinish() {         cleardbs();     } };  private void cleardbs() {     // clearing databases here     cleardbscountdowntimer.start(); } 

but it's not working: think because cleardbs() method waits countdowntimer finish, right?

but how correctly: ideas?

alarmmanager + intentservice cleanest approach.

with alarmmanager can schedule periodic intentservices.

an intentservice service performs specific action in background thread (onhandleintent() call) , dies.

they make perfect mix perform periodic jobs in background.

check example this post.

please careful kind of operations since result in draining battery (and having angry users).

as suggested @squonk can use setrepeating(...) or setinexactrepeating(...) schedule periodic events.

if want perform background task when app in foreground, can still cancel event calling manager.cancel()


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -