I have a simple c2dm message receiver class which is called whenever the device receives a c2dm message. In one case, I want to have the message receiver class perform an intent switch to load a different activity. Android throws an exception when this happens
01-07 02:28:52.480: E/AndroidRuntime(440): Caused by: 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 guess I could investigate this flag suggested in the exception, but i’m wondering if maybe i’m taking the wrong approach and there is a better way to do this?
c2dm message receiver class:
public class C2DMMessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.w("C2DM", "Message Receiver called");
if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
Log.w("C2DM", "Received message");
final String payload = intent.getStringExtra("payload");
Log.d("C2DM", "dmControl: payload = " + payload);
// Message handling
if(payload.equals("RdyRoom::join")) {
Intent rIntent = new Intent(context.getApplicationContext(), ReadyRoomActivity.class);
context.startActivity(rIntent);
}
}
}
}
Thanks for any ideas
Add this to your intent