0

So I have been playing with Tasker for Android and have it firing intents to my Service running in the background. However my service only receives the intent every other time. I have another task on the same profile that displays a notification and it pops up every time. Not sure if this is a problem with Tasker or a problem with the app. Here is my service which is running in the background using a Broadcast Receiver to listen for the intent:

package com.controlanything.garageapp;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.widget.Toast;

public class IOService extends Service {
    private static final String ACTION ="com.controlanything.garageapp.IO_ACTION";
    private BroadcastReceiver bReceiver;
    public IOService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onCreate(){
        super.onCreate();
        System.out.println("Service started.");
        final IntentFilter theFilter = new IntentFilter();
        theFilter.addAction(ACTION);
        this.bReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if(intent.getStringExtra("COMMAND").equalsIgnoreCase("ON")){
                    System.out.println("On Command");
                    makeToast("ON!");

                }else{
                    System.out.println("Off Command");
                    makeToast("OFF!");
                }
            }
        };
        this.registerReceiver(this.bReceiver, theFilter);
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        this.unregisterReceiver(this.bReceiver);
    }
    private void makeToast(String message){
        Toast.makeText(this, message, Toast.LENGTH_LONG);
    }

}

Any ideas much appreciated.

Travis Elliott
  • 291
  • 2
  • 5
  • 18
  • You have created an empty constructor for your service. Don't do that. Remove it. – David Wasser May 07 '15 at 21:50
  • Thanks David. I actually got rid of the service completely and implemented a stand alone broadcast receiver and had it trigger an Intent service. All is working as expected now. – Travis Elliott May 08 '15 at 15:41

0 Answers0