【问题标题】:extras(notification text) doesn't get passedextras(通知文本)没有通过
【发布时间】:2020-04-02 00:49:13
【问题描述】:

附加信息(通知文本)没有传递给 textView,(文本视图显示为空),有什么问题? 这是相关代码:

AlarmReceiver 扩展 BroadcastReceiver : https://textuploader.com/1j851

通知活动(应该显示文本): https://textuploader.com/1j85j

我的主要活动: https://textuploader.com/1j8tr

如果我犯了任何愚蠢的错误,请原谅,我是编程新手

【问题讨论】:

    标签: java android-intent notifications


    【解决方案1】:

    我想这是你的问题。您在这里传递了错误的值。您创建了一个对象 i,但您使用的是 intent 对象。

        Intent i = new Intent(context,
                NotificationActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.putExtra("message",x);
        PendingIntent pendingIntent = PendingIntent.getActivity(context,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
    

    所以像下面这样使用。

        Intent i = new Intent(context,
                NotificationActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TASK); //i 
        i.putExtra("message",x); //i
        PendingIntent pendingIntent = PendingIntent.getActivity(context,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
    

    【讨论】:

      猜你喜欢
      • 2011-11-14
      • 2012-11-15
      • 2019-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多