Reputation: 2532
In my app I show notification in some cases and when user click on notification it navigate to app by this code:
Intent onNotificationClicked = new Intent(G.context, MainActivity.class);
onNotificationClicked.putExtra("DO", "clicked");
onNotificationClicked.setAction(Intent.ACTION_MAIN);
onNotificationClicked.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent ponNotificationClicked = PendingIntent.getActivity(ctx, 113, onNotificationClicked, PendingIntent.FLAG_UPDATE_CURRENT);
this.contentIntent = ponNotificationClicked;
now in my MainActivity I want to get extras of this intent.but that is unavailable because this intent does not make a new activity and just bring the launched activity to front.so how can I handle this kind of intent in my app.
thank you
Upvotes: 1
Views: 2447
Reputation: 2532
I found the answer:
set in manifest in your activity:
android:launchMode="singleTask"
and then for your pending intent you should to set like this:
Intent onNotificationClicked = new Intent(G.context, MainActivity.class);
onNotificationClicked.putExtra("DO", "clicked");
PendingIntent ponNotificationClicked = PendingIntent.getActivity(ctx, 113, onNotificationClicked, PendingIntent.FLAG_UPDATE_CURRENT);
this.contentIntent = ponNotificationClicked;
and now in your activity override onNewIntent and in it writ your function:
@Override
protected void onNewIntent(Intent intent) {
String action = intent.getStringExtra("DO");
if (action != null) {
Log.d("this is creating", "shiva said right");
mSlidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
}
super.onNewIntent(intent);
}
Upvotes: 1