Android - 从小部件调用 Activity

发布于 2024-08-16 11:01:49 字数 407 浏览 4 评论 0原文

目前,我的应用程序 HireADroid 的小部件与主应用程序捆绑在一起。我想解除该小部件的捆绑并将其作为单独的产品发布。但是 - 该小部件依赖于主应用程序中的 Activity,因此我需要在这两个小部件之间导航,主要从小部件调用主应用程序的特定 Activity。所以基本的想法是——应用程序可以在没有小部件的情况下工作,并且小部件成为“附加”选项。

从独立小部件调用应用程序活动的“正确”方法是什么?我是否要将主应用程序转换为内容提供商?您能给我指出任何代码示例吗?

新年快乐!

PS 我不是问如何从捆绑在同一个 APK 中的小部件调用 Activity。该问题特别指出小部件与它所调用的应用程序分开分发

I currently have widget for my app HireADroid bundled with the main application. I would like to unbundle the widget and release it as a separate offering. However - the widget is relying on Activities from the main app so I need to navigate between these two mainly calling particular Activity of the main app from the widget. So the basic idea - app can work without widget and the widget becomes the "add-on" option.

What is the "right" way to call app activities from the stand-alone widget? Do I convert the main app into a content provider? Can you point me to any code samples perhaps?

Happy New Year!

P.S. I'm not asking how to call Activities from the widget that is bundled in the same APK. The question specifically states that widget is distributed separately from the app it's calling

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゃ懵逼小萝莉 2024-08-23 11:01:49

基本思想是使用意图:

  1. 在清单中,让您的活动使用 响应某些操作。
  2. 在您的小部件代码中,为您设置的 Activity 响应的操作创建 android.content.Intent 类的实例,并在 Intent 实例上调用 startActivity

如果活动是上下文相关的,您可以使用内容 URI(您可以为操作/URI 对创建 Intents),还可以通过“extras”包传递额外信息(请参阅 Intent.getExtras)。

更多信息请参阅此处的文档:

The basic idea is to use Intents:

  1. In the manifest, have your activity respond to certain actions using an <intent-filter>.
  2. In your widget code, create an instance of the android.content.Intent class for the action you've set your activity to respond to, and call startActivity on the Intent instance.

If the activity is contextual, you can use content URIs (you can create Intents for action/URI pairs) and also pass extra information via an 'extras' bundle (see Intent.getExtras).

More information available in the docs here:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文