Android: how to start a service at boot based on user-settings?

Posted by Cicerone Cojocaru on Stack Overflow See other posts from Stack Overflow or by Cicerone Cojocaru
Published on 2010-05-06T15:51:19Z Indexed on 2010/05/06 17:38 UTC
Read the original article Hit count: 149

Filed under:

Hey everyone, I'm trying to write an app that consists of an activity that manages a background service. However, I want to implement a user setting for automatically starting the service up at boot time. I have user settings implemented with SharedPreferences and I have the services starting up at boot by using a BroadcastReceiver and listening for BOOT_COMPLETED.

However, I can't figure out a good way to implement a setting so that the service is only started at boot if said setting is enabled. I can think of a few cheap ways to do this (such as messing with onCreate() in the service, or creating/checking for a file on SD card) but I want to follow good practice.

There must be a good way to do this because there's tons of apps out there that do it, I just can't find anything online about how to do it.

Thanks

© Stack Overflow or respective owner

Related posts about android