Damir
Damir

Reputation: 56179

IntentService doesn't start from BroadcastReceiver

I am trying to start IntentService from BroadcastReceiver like ( in onReceive(Context context, Intent intent) function):

            Intent i = new Intent(context, RegService.class);
            i.putExtra("user_id", userId);
            i.putExtra("device_id", "bla");
            context.startService(i);

and RegService like

public class RegService extends IntentService {

    public RegService(String name) {
        super(name);
    }

    public RegService(){
        super("RegService");    
    }



    @Override
    protected void onHandleIntent(Intent intent) {
        // TODO Auto-generated method stub
        String c2dm_registration_id = intent
                .getStringExtra("c2dm_registration_id");
        String token = intent.getStringExtra("token");
        String userId = intent.getStringExtra("user_id");
        String device_type = "android";
        try {

            JSONObject object = RestClient.sendC2DMRegistrationId(
                    c2dm_registration_id, device_type,
                    token, userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

but I cannot enter in onHandle in RegService ( I passed through first code context.startService(i); but I cannot enter in onHandle, no message ). Did anybody have same experience and waht is a solution ? I have in manifest

<service
        android:enabled="true"
        android:name=".c2dm.RegService" />

Upvotes: 2

Views: 3569

Answers (2)

Basher51
Basher51

Reputation: 1329

When my IntentService was declared with just its class name in the manifest,then I was not able to call it from the Broadcast Receiver.I then gave the full name like :

<service  android:name="com.abc.def.services.DummyService" />

This did the trick and I was able to invoke this IntentService from within the Broadcast Receiver.

Upvotes: 3

gwvatieri
gwvatieri

Reputation: 5173

Have you declared the service in the manifest?

If so and it does not work try to set an action on the intent anyway, evenhough you won't use it.

Upvotes: 1

Related Questions