I have a broadcast receiver (c2dm push receiver).
When i receive a push, i want this to happen:
- Start a notification, where you are led to StopAlarmActivity (Done!)
- If the application are in front, start StopAlarmActivity (How can i check this)
My main problem is that i can’t get the broadcast receiver to start the StopAlarmActivity for me.
I have registered the broadcast receiver in the manifest.
Here’s the code i use to try to start an activity:
Intent intentHome = new Intent(context, StopAlarmActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentHome);
This is the stacktrace message:
11-20 00:29:30.514: E/AndroidRuntime(13612):
java.lang.RuntimeException: Unable to start receiver
com.packagename.PushReceiver: android.util.AndroidRuntimeException:
Calling startActivity() from outside of an Activity context requires
the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
I’ve seen some people saying it’s just to add FLAG_ACTIVITY_NEW_TASK to the intent, and the exception is also telling me that, so i really don’t understand why it’s not working.
Anyone got an idea?
Thanks in advance!
In your code you have:
but your intent for this new activity is
intentHome. Change that line to: