• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Rules for Android background tasks (or apps)

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a recent Android developer. I have an app that I'd like to work in the background, going to "sleep" for most hours each day and, at other times, checking for server state every 1 hour and, over a brief period of just a few hours, every 10 minutes or so. If there were a change in state, it might display some notice of this (a Toast or something else appropriate).

I've pored over myriad posts and discussions about how "evil" background apps are on Android. There are even apps created to help the device owner manage, especially, kill them. I certainly do not want my app to do the wrong thing.

I have also read that the Android OS will actually kill apps that aren't in active use. My app would probably be asleep from late evening until early to mid-afternoon knowing that there would be no server state to be concerned about until then. Would it not therefore be tossed out and no longer in the background?

I'm interested in a link to an authoritative article that covers the best practice for such things and, if possible, good design for them as well. Alternatively, my ears are wide-open if someone wanted to pontificate directly here. I would be most grateful for any and all comments.

Thanks,

Russ Bateman
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Android may kill Activities that are not in use. But Activities are supposed to interact with the user, and they can't do that anyway if they're in the background. But there are also Services, which run only in the background, and sound exactly like what you're looking for. See http://developer.android.com/guide/topics/fundamentals.html for descriptions of the basic building blocks for Android apps.

And yes, a user -or a process manager he configures accordingly- can kill any process, but presumably a user would want your background service to run; so I don't see that as a problem.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic