【问题标题】:Make Pending Intent usable in any class使 Pending Intent 可用于任何类
【发布时间】:2015-08-27 18:28:52
【问题描述】:

我需要能够在我的任何类中使用我在 Java 类中创建的 Pending Intent 我该怎么做?

PendingIntent notifIntent;
notifIntent = notification.contentIntent;

需要使用它的原因是因为我将 Pending Intent 设置为 Notifications Pending Intent 是什么,然后在我的主要活动的 onClick 事件中我需要引用这个值。

【问题讨论】:

  • 您需要更好地解释您的用例:您是否需要能够更新全局 PendingIntent,或者您只是想从应用程序的任何地方访问一个永不更改的 PendingIntent ?
  • @jvmk 我只想能够访问它我不想改变它
  • 好的,它是如何实例化的?可以静态实例化吗?

标签: java android android-pendingintent


【解决方案1】:

好吧,这个问题的答案可能是为此创建一个课程。您可以在代码中的任何位置访问的内容。

public class PendingIntentHolder {
    public static PendingIntent instance = new PendingIntent();
    static PendingIntent pendingIntent;

    public static void setPending(PendingIntent intent) {
        pendingIntent= intent;
    }

    public static PendingIntent getPending() {
        return pendingIntent;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-13
    • 1970-01-01
    • 2013-02-24
    • 1970-01-01
    相关资源
    最近更新 更多