将现有的应用程序到库 [英] Converting an existing Application to a Library

查看:143
本文介绍了将现有的应用程序到库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将现有的Andr​​oid应用程序到库是<一个href=\"http://developer.android.com/guide/developing/projects/projects-eclipse.html#SettingUpLibraryProject\"相对=nofollow>难以置信的简单:我所要做的就是检查是库复选框中的项目的属性。

Converting an existing Android application to a library is incredibly simple: All I have to do is check the is Library checkbox in the project's properties.

然而,一旦这个简单的步骤得到了应用,一个更严肃的任务摆在面前:如何留住原来的应用程序code不变(!作为一个库),同时构建基于它不同的应用

However, once this easy step has been applied, a much more serious task lies ahead: How to retain the original application code unchanged (as a library!), while building different applications based on it.

这是,我真的不希望添加其他的活动,但(在库现在),而重新使用原来的活动,在这里只有几个方法(在且仅一个活动)是在不同的每个派生的应用程序。

That is, I don't really want to add another activity, but rather re-use the original activity (now in a library), where only a few methods (in the one-and-only activity) are different in each derived application.

是解决方案确实是在此基础上每个应用程序继承了图书馆的活动那么简单?

Is the solution really is as simple as subclassing the library's activity in each application based on it?

我应该注意哪些注意事项?

What caveats should I watch for?

有没有更好的方法吗?

推荐答案

您将主要不得不从包括在librairy的那些派生新类或调用它们的方法。如果您有librairy类,如活动,应用程序,你可以扩展他们有你说的。

You will mostly have to derive new classes from the ones included in the librairy or call their methods. If your librairy has classes such as activities, applications, you can extends them has you said.

另一种解决办法是隔离你想重用和plugit成依赖其他活动code注射。但是,这似乎框架矫枉过正我在那里你可以派生新类。

Another solution could be to isolate the code you want to reuse and plugit into other activities by dependency injection. But this framework seems an overkill to me where you can just derive new classes.

一个更多的Andr​​oid具体的问题可能是:如何调用从我的新应用程序中我的新活动。这里的答案依赖于意图和使用不同的操作名称,呼吁扩展活动。

A more android specific problem could be : how to call my new activities from within my new applications. The answer here relies in intent and to use different action names to call for the extended activities.

问候,
 斯特凡

Regards, Stéphane

这篇关于将现有的应用程序到库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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