0
@Override
protected void onMessage(Context context, Intent intent) {
    Log.e("C2DM", "Neue Message.");
    Intent resultIntent = new Intent(context, ResultActivity.class);
    resultIntent.putExtra("message", "Message received");
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

I can see from my logcat that i get into this method, then when it tried to start the activity, it throws the fatal exception as written in title with the following comment:

android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? (my reply to AndroidRuntime is: "Isn't that what I'm doing?") ;-)

silwar
  • 6,470
  • 3
  • 46
  • 66
Anders Metnik
  • 6,096
  • 7
  • 40
  • 79

1 Answers1

0

You are passing the wrong intent variable to startActivity() call. You want to use resultIntent to start the new activity and you are adding FLAG_ACTIVITY_NEW_TASK flag to resultIntent but when starting the new activity you are passing intent by mistake i.e

resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

change this to

resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(resultIntent);
binW
  • 13,220
  • 11
  • 56
  • 69