tags:

views:

136

answers:

2

I am trying to call a push notification background service from BroadcastReceiver class, but my application crashes. The code is given below:

public class AlarmReceiver extends BroadcastReceiver {

    static int count=1;

    @Override
    public void onReceive(Context context, Intent intent) {

        Intent myIntent=new Intent(context,NotifyService.class);
        myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        context.startActivity(myIntent);  
    }
} 

The manifest entry:

<receiver android:name=".AlarmReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
    </intent-filter>
</receiver>
<service android:name=".NotifyService">
</service>

The error:

05-24 15:17:00.042: ERROR/AndroidRuntime(424): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.alarm/com.android.alarm.NotifyService}; have you declared this activity in your AndroidManifest.xml?

When I call this service through an Activity it's working, but my goal is to call this service from a BroadcastReceiver.

+1  A: 

AlarmReceiver is calling startActivity(), not startService(). You start services with startService(); you start activities with startActivity().

Also, services do not need (or use, AFAIK) FLAG_ACTIVITY_NEW_TASK.

CommonsWare
Oh!!! yaa... thanks CommonsWare..... now its working...
Shalini Singh
+1  A: 

It is fine to use C2DM for push notification in Android......May this will be your solution......

Nirav Shah