【问题标题】:how to open particular fragment which in an activity when notification is clicked单击通知时如何打开活动中的特定片段
【发布时间】:2016-12-21 15:39:52
【问题描述】:

我在通知栏中有一个通知,并且我的一个活动中有 3 个片段。 当我单击通知时,我希望它会打开特定的片段,就像 facebook 通知所做的那样。我试图在谷歌和其他任何地方搜索它,但没有找到我需要的东西。

示例:我有 3 个片段

  1. 兑换价值。
  2. 用于充电。
  3. 任何东西。

现在,如果我从管理面板收到通知,例如您可以兑换您的价值,那么该通知将打开该特定片段。如果我收到充电通知,那么它将打开那个特定的片段,就像我希望它工作一样。

希望你清楚,如果没有,请告诉我。

【问题讨论】:

  • 有什么问题?只需打开您的活动并将您想要的任何片段添加到活动中。
  • 但在启动应用程序时无法正常工作。在服务类中,除此主活动外,还有 startId 变量,剩余值为 1。对于此 homeactivity,startId 为 2。如何清除堆栈值
  • 你能说清楚一点吗?贴出相关代码和发生的错误。
  • 如何取消当前活动的片段?我正在使用 FLAG_CANCEL_CURRENT 但是,它不起作用
  • 新启动的应用程序可以完美地处理通知,但是已经存在的应用程序没有正确响应通知

标签: android android-fragments android-notifications android-notification-bar


【解决方案1】:

这是你的做法

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);

您还可以相应地设置参数

【讨论】:

  • if(category.equalsIgnoreCase("Tips")){ intent = new Intent(this, TipsFeedActivity.class); }else if(category.equalsIgnoreCase("Album") || category.equalsIgnoreCase("EventAdd") || category.equalsIgnoreCase("EventJoin") || category.equalsIgnoreCase("EventExcuse") || category.equalsIgnoreCase("FeedWall ")){ intent = new Intent(this, HomeActivity.class); }else if(category.equalsIgnoreCase("GuestJoin")){ intent = new Intent(this, GuestJoinWeddingActivity.class); }else { intent = new Intent(this, SplashActivity.class); }
  • 这是 gcmIntentservice 类
  • 我怎样才能相应地设置我的参数 bcz,我对这个主题很陌生,请帮助我
  • 新启动的应用程序可以完美地处理通知,但是已经存在的应用程序没有正确响应通知
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-19
相关资源
最近更新 更多