简体   繁体   English

单击通知时如何打开活动中的特定片段

[英]how to open particular fragment which in an activity when notification is clicked

I have a notification in notification bar and I have 3 fragments in one of my activity. 我在通知栏中有一个通知,我的一项活动中有3个片段。 When I click the notification, I want that it will open particular fragment, Like what facebook notification do. 当我单击通知时,我希望它会打开特定的片段,就像facebook通知那样。 I tried to search it on google and everywhere else but didn't found what I need. 我试图在Google和其他任何地方搜索它,但没有找到我需要的东西。

Example: I have 3 fragments 示例:我有3个片段

  1. for redeem value. 兑换价值。
  2. for recharge. 充电。
  3. for anything. 为了任何东西。

Now if i get notification from Admin Panel like you can redeem your value, then that notification will open that particular fragment. 现在,如果我从管理面板收到通知(如可以兑换您的值),则该通知将打开该特定片段。 If i get notification to recharge then it will open that particular fragment, like this i want it working. 如果我收到充电通知,它将打开该特定片段,像这样,我希望它正常工作。

Hope you are clear, if not then please let me know. 希望您清楚,否则请通知我。

Here is how you do it 这是你的做法

mNotificationManager = (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

        notificationBuilder = new NotificationCompat.Builder(context);    

Intent resultIntent = null;

resultIntent = new Intent(context.getApplicationContext(), MainActivity.class);

TaskStackBuilder stackBuilder = TaskStackBuilder.create(context.getApplicationContext()); 

        stackBuilder.addParentStack(MainActivity.class);

        stackBuilder.addNextIntent(resultIntent);

notificationBuilder.setContentIntent(resultPendingIntent);

Further you can set your param's accordingly 此外,您可以相应地设置参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM