什么是对磨损和Android应用程序之间共享类的最佳做法?磨损、应用程序、做法、Android

2023-09-05 03:17:09 作者:妳的傲慢我的偏見

我使用的序列化在我的Andr​​oid手机的应用程序,和反序列化在我的Andr​​oid Wear应用程序的类。它们都在相同的机器人工作室项目,并且被部署为一体。

I'm using a class that I serialize in my Android Phone app, and deserialize in my Android Wear app. They are both in the same Android Studio Project, and are deployed as one.

我如何可以共享这两个之间的阶级,而不必每个包中的类的副本?现在我复制/粘贴,但有什么办法,我把它列入这两个应用程序?

How can I share the class between the two without having a copy of the class in each package? Right now I'm copy/pasting it, but is there any way for me to include it in both apps?

的目录结构存在:

./
    mobile/
           ...src/etc
    wear/
           ...src/etc

我如何处理常见的班?

How do I handle common classes?

推荐答案

您可以在项目中创建一个新的Android库模块,然后将您的通用类存在。

You can create a new "Android Library" Module in the project, and place your common classes there.

然后你只需将其添加为两个移动的依赖,并佩戴模块(在项目结构 - >相关性 - >添加 - >模块依赖)。这样,你可以创建/使用这些类的实例从两个模块。

Then you simply add it as a dependency of both the Mobile and Wear modules (in Project Structure -> Dependencies -> Add -> Module dependency). That way you can create/use instances of these classes from both modules.

 
精彩推荐
图片推荐