lLaunch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); This is needed .. because broadcast receiver could have different context
On Mar 12, 2:48 pm, vani reddy <vani.reddy.bl...@gmail.com> wrote: > Hi friends, > > I am using Urbanairship for push notifications. > > I am getting the following exception > > Unable to start receiver com.testdemo.android.IntentReceiver: > android.util.AndroidRuntimeException: Calling startActivity() from > outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK > flag. Is this really what you want? > > and the below is the onReceive of IntentReceiver > > @Override > public void onReceive(Context arg0, Intent aIntent) { > String action = aIntent.getAction(); > if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) { > // user opened the notification so we launch the > application > > // This intent is what will be used to launch the > activity in our > // application > Intent lLaunch = new Intent(Intent.ACTION_MAIN); > > // Main.class can be substituted any activity in your > android > // project that you wish > // to be launched when the user selects the > notification from the > // Notifications drop down > > lLaunch.setClass(UAirship.shared().getApplicationContext(), > HomeScreen.class); > > > lLaunch.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); > > // copy the intent data from the incoming intent to > the intent > // that we are going to launch > > // copyIntentData(aIntent, lLaunch); > > > UAirship.shared().getApplicationContext().startActivity(lLaunch); > > } else if (action.equals(PushManager.ACTION_PUSH_RECEIVED)) { > // push notification received, perhaps store it in a > db > > } > > } > > -- > Regards, > Vani Reddy -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en