android android P 中的 AppComponentFactory - 如何 wrap/decorate 功能围绕外部 activity

android AppComponentFactory in android P - how to wrap/decorate functionality around an external activity

来自 the docs 我们看到我们能够通过工厂方法提供活动。

所以我正在研究一个解决方案,我可以在其中使用 activity 并在其上装饰功能。但我不拥有这些活动。我只知道那里的名字。所以这就是我到目前为止所拥有的:

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
AppComponentFactory.instantiateApplication(classLoader, SomeoneElsesActivity.class.name)

我将从我自己的 activity 调用它来打开 SomeoneElsesActivity.class 。但我不清楚如何添加额外的功能。我会在 activity 打开后生成像 Intent 服务这样的后台服务吗?

如果我能够使用包装器,是否有办法禁止其他人对我的 activity 执行此操作?我不希望任何其他开发人员能够使用我的 activity 并围绕它包装功能并再次调用它。

更新 2018-06-03AppComponentFactory 适用于 P DP2。

from the docs we see we are able to provide an acitivity through factory method.

更重要的是,您通过 android:appComponentFactory 在清单中注册了 AppComponentFactory。然后 your process crashes, because AppComponentFactory will not be working until the next developer preview.

i will be calling this from my own activity to open SomeoneElsesActivity.class

据我所知,这不是您使用 AppComponentFactory 的方式。 AppComponentFactory 为用于创建 activity 个实例的框架提供回调。

and if i am able to use the wrapper is there a way to disable other people from doing this to my activity ?

不要运送图书馆。欢迎包含您的库的应用程序的开发人员在其应用程序的上下文中做任何他们想做的事情。

如果您指的是有人重新打包您的应用程序,他们无论如何都可以这样做——这只会让这项工作的一个方面变得更容易。原则上,您可以检查 activity 的 zero-argument 构造函数中的 Java 调用堆栈,尝试确定是否有人正在使用 AppComponentFactory,然后采取措施。我不知道从长远来看这会有多实用......特别是因为 AppComponentFactory 似乎不起作用。