I have a Sencha Touch + Phonegap application which is required to handle push notifications. When the app is not running, or in the background, and notificatiion arrives, the user taps the notification, and the app is opened, and he is properly navigated to the respective page in the Sencha Touch app.
The problem is when the app is already in the foreground.
I am also using Urbanairship Library in this app. And in the Urbanairship configuration, I have to specify the activity that should be opened when a user taps on the Notification.
And the configuration is as follows:
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); if (intent.getAction().equals( "com.urbanairship.push.NOTIFICATION_OPENED")) { Intent openIntent = new Intent(context, MainActivity.class); openIntent.setAction(intent.getAction()); openIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); openIntent.putExtra("where", "push"); openIntent.putExtra("data", intent.getExtras()); context.startActivity(openIntent); } }
Now, if I specify the flag as NEW_TASK, it opens up another instance of the app, which again reloads everything. And then would go to the corresponding page to handle the notification.
If I don't use the NEW_TASK flag, the app crashes, since it's being called from a non-activity context.
How should it set this up so that I don't create a new instance of the app, if the app is already in the foreground?