【问题标题】:How to launch a new activity using pending intent [closed]如何使用待定意图启动新活动 [关闭]
【发布时间】:2011-12-15 08:23:55
【问题描述】:

谁能说一下如何使用PendingIntent 启动一个新的Activity 并使用挂起的意图传递一个值。 提前致谢。

【问题讨论】:

    标签: android android-intent android-pendingintent


    【解决方案1】:
    Intent intent = new Intent(getApplicationContext(), ActivityToLaunch.class);
    intent.putExtra(<oneOfThePutExtraFunctions>);
    PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
    

    您可以使用位于以下位置的各种 Intent.PutExtra() 函数之一将额外数据添加到 Intent:http://developer.android.com/reference/android/content/Intent.html

    然后,当您准备好启动 PendingIntent 时,使用位于以下位置的 Send() 函数之一:http://developer.android.com/reference/android/app/PendingIntent.html

    【讨论】:

    • PendingIntent.getActivity 的文档说“请注意,该活动将在现有活动的上下文之外启动,因此您必须在 Intent 中使用 Intent.FLAG_ACTIVITY_NEW_TASK 启动标志”。所以你可能应该这样做intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多