gpt4 book ai didi

机器人 : how does the OS chose a component implementation when multiple implementation respond to the same intent?

转载 作者:行者123 更新时间:2023-11-29 14:11:55 26 4
gpt4 key购买 nike

我有同一个应用程序的免费版和高级版(几乎相同的代码,相同的类,到处都是“if”, list 中的不同包, list 中的进程名称相同)。主要 Activity 使用 IMPLICIT Intent 调用服务来执行某些操作。

当我在手机上安装这两个应用程序时,事实证明高级 Activity 实际上有时会启动“免费”服务,有时会启动“高级”服务。我一直在研究类别和包管理器,但它似乎太复杂了。

问题:

  1. Android 如何处理响应同一 Intent 的多个组件?
  2. 你会如何做我想做的事情:我在多个应用程序中有相同的服务,我只希望从所有应用程序调用一个实例?

最佳答案

我想您可以在 Intent 中添加一个额外的 bool 值 isPremium。自然地,您将需要更多这些“如果”。

Activity :

//send broadcast
Intent serviceStarted = new Intent(Actions.ACTION_START_SERVICE);
serviceStarted.putExtra(Extras.EXTRA_PREMIUM_VERSION, PREMIUM_VERSION);
sendBroadcast(serviceStarted);

接收者:

if (!intent.getExtras().getBoolean(Extras.EXTRA_PREMIUM_VERSION)) {
Log.v(TAG, " - ignoring wrong version");
return;
}

关于机器人 : how does the OS chose a component implementation when multiple implementation respond to the same intent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1775660/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com