简体   繁体   English

当在消费应用中定义 Activity 时,从 Android 库启动 Activity

[英]Launching activities from Android Library when Activity is defined in the consuming App

I have an app which I am trying to turn into a library and create 2 new apps that consume it.我有一个应用程序,我正试图将它变成一个库并创建 2 个使用它的新应用程序。 I have to move all code differences between the 2 apps out of the library and into the separate apps due to the fact that I sold the source code to the client of the app.由于我将源代码出售给了应用程序的客户端,因此我必须将 2 个应用程序之间的所有代码差异移出库并进入单独的应用程序。 This way I can give them the library and their app.这样我就可以给他们图书馆和他们的应用程序。 I am running into a bit of a problem tho.我遇到了一些问题。 In at least one of my activities the UI behavior is somewhat different, in this case the CustomerListActivty.在我的至少一项活动中,UI 行为有些不同,在本例中是 CustomerListActivty。 So I started to move the CustomerListActivity out into each respective app, but the problem came when other activities in the library project were trying to invoke the CustomerListActivity via startActivity(new Intent(SomeClass.this, CustomerListActivity.class));.所以我开始将 CustomerListActivity 移到每个相应的应用程序中,但是当库项目中的其他活动试图通过 startActivity(new Intent(SomeClass.this, CustomerListActivity.class)); 调用 CustomerListActivity 时,问题就来了。 Obviously the library no longer knew what CustomerListAcitivity was so I got compiler errors.显然库不再知道 CustomerListAcitivity 是什么,所以我得到了编译器错误。 I am at a loss on how to solve this problem.我不知道如何解决这个问题。 I think I need some way to refer the activity other than by class name.我想我需要一些方法来引用活动,而不是通过 class 名称。

Thank you for any and all help!感谢您的任何帮助!

Aaron亚伦

Take a look at implicit intents and intent filters for when you don't want to specify exact classes and paths.当您不想指定确切的类和路径时,请查看隐式意图和意图过滤器

You can launch Activities without specifying the class name.您可以在不指定 class 名称的情况下启动活动。 You can send an Intent with an Action rather than Activity and have you Activity specify a filter for that action.您可以发送带有 Action 而不是 Activity 的 Intent,并让 Activity 为该操作指定过滤器。 It'll be launched when Action is received.它会在收到 Action 时启动。 The Android dev guide has a useful tutorial on how to do that. Android 开发指南有一个关于如何做到这一点的有用教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:从主应用程序启动库活动 - Android: Launching Library Activity from Main App 从库项目启动Android活动时出错 - Error Launching Android Activity From Library Project 从另一个应用程序活动启动时,Android应用程序活动将启动,但不会在其上启动。 - Android app activity launches when launching from another app activity but doesn't launch on its on. android阻止后台应用程序在前台启动活动 - android Prevent a background app from launching activities in the foreground 处理android.intent.action.VIEW时,Android启动活动会位于其他活动之上 - Android launching activity on top of other activities when handling android.intent.action.VIEW 从Android应用安装程序和主屏幕启动应用程序时的活动堆栈排序问题 - Activity stack ordering problem when launching application from Android app installer and from Home screen 从后台启动活动,而不将其附加到同一应用程序现有活动的任务堆栈中 - Launching an Activity from the background without attaching it to the task stack of existing activities of the same app 从广播接收器启动活动时如何完成所有先前的活动 - How to finish all previous activities when launching activity from broadcast receiver 启动应用程序时活动被破坏 - Activity destroyed when launching app 从android应用程序启动未知活动 - Launching unknown activities from an android application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM