【问题标题】:Handling multiple intent call处理多个意图调用
【发布时间】:2014-07-30 08:30:16
【问题描述】:

我正在使用显式意图将消息从我的 App1 传递到我的另一个应用 App2。
它与以下代码很好地配合使用:

Intent intent = new Intent();
intent.setComponent(new ComponentName("mypkg","mypkg.myactivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("Key1", "MyCustomValue1");
startActivity(intent);

但是,我想通过 Intent 发送后续消息(在发送初始 Intent 之后),但是一旦 App2 启动并发送后续 Intent,App2 中的 onCreate() 就不会再次被命中。那么,我怎样才能得到它,以便我可以向 App2 发送多个意图并在 App2 中捕获每个意图?

(是的,我知道这里的服务会更好,但是这种设计超出了这个问题的范围。)

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    但是一旦 App2 启动并且我发送后续意图,App2 中的 onCreate() 就不会再次被命中

    它们正在发送到您的活动实例中的onNewIntent()

    是的,我知道这里的服务会更好

    或者可能是事件总线,例如 greenrobot 的 EventBus、LocalBroadcastManager 或 Square 的 Otto。

    【讨论】:

    • 谢谢!像魅力一样工作。顺便说一句 - 我必须在随后的意图调用中添加 FLAG_ACTIVITY_SINGLE_TOP 标志才能触发 onNewIntent()。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 2016-06-02
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多