[英]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.