Starting Background Location Service not working

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Sep 17, 2014 6:37:53 PM via Website

I have some problems with using a Background Location Service for android. I started using this code and modified it for my needs: ""

Here are the modified parts for LocationLoggerServiceManager:

I changed the part, so I can start this service manually with an own broadcast.

public class LocationLoggerServiceManager extends BroadcastReceiver {

    private SharedPreferences mPrefs;
    public static final String TAG = "LocationLoggerServiceManager";
    public void onReceive(Context context, Intent intent) {
        // Make sure we are getting the right intent
        if( "android.intent.action.BOOT_COMPLETED".equals(intent.getAction()) || "".equals((intent.getAction()))) {
            boolean mUpdatesRequested = false;
            // Open the shared preferences
            mPrefs = context.getSharedPreferences("ftm.vem_game.shared_preferences",
             * Get any previous setting for location updates
             * Gets "false" if an error occurs
            if (mPrefs.contains("KEY_UPDATES_ON")) {
                mUpdatesRequested = mPrefs.getBoolean("KEY_UPDATES_ON", false);
                //ComponentName comp = new ComponentName(context.getPackageName(), BackgroundLocationService.class.getName());
                //ComponentName service = context.startService(new Intent().setComponent(comp));

                Intent i = new Intent(context, BackgroundLocationService.class);
                ComponentName service = context.startService(i);

                if (null == service){
                    // something really wrong here
                    Log.e(TAG, "Could not start service BackgroundLocationService");

        } else {
            Log.e(TAG, "Received unexpected intent " + intent.toString());

And here is the part where I send the Broadcast in my MainActivity class:

public static final String BROADCAST = "";
                SharedPreferences sharedPref = getSharedPreferences("ftm.vem_game.shared_preferences", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putBoolean("KEY_UPDATES_ON", true);

                Intent intent = new Intent(BROADCAST);
                Bundle extras = new Bundle();
                extras.putString("send_data", "test");

On the service class I changed nothing. The problem is the service never starts, in the Log it says "Could not start service BackgroundLocationService". And context.startService() returns everytime null.

I dont know what I do wrong or maybe I miss something to do before starting the service.