什么是对磨损和Android应用程序之间共享类的最佳做法? [英] What's the best practice for sharing classes between a Wear and Android app?

查看:201
本文介绍了什么是对磨损和Android应用程序之间共享类的最佳做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的序列化在我的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.

这篇关于什么是对磨损和Android应用程序之间共享类的最佳做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆