清单中的 Android 抽象活动 [英] Android abstract activity in manifest

查看:28
本文介绍了清单中的 Android 抽象活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的应用程序,我将创建各种抽象类来扩展 android.app.Activity 和 android.app.Service 类.

For my application I am going to create a variety of abstract classes that extend the android.app.Activity and android.app.Service classes.

  • 当我对抽象类进行子类化时,如何将它们添加到 android manifest?
  • 我需要将抽象类和我的子类都添加到清单中还是只添加子类?
  • 它们需要在同一个包裹中吗?

推荐答案

您将最终的子类作为常规活动/服务添加到清单中;抽象类不需要在那里,因为清单只是一个查找,所以系统知道要启动哪个类来响应 Intent

You add the final subclasses to the manifest as regular Activities/Services; the abstract classes don't need to be there, as the manifest is only a lookup so the system knows which class to launch in response to an Intent

如果包"是指 Java 包(例如 com.mycompany.whatever),则不,只需在创建子类时添加相关导入(或使用完全限定名称).

If by 'package' you mean Java package (e.g. com.mycompany.whatever), then no, just add the relevant import (or use the fully qualified name) when creating the subclass.

如果包"是指 APK,那么是的,抽象基础应该与常规代码一起在那里,虽然可以在 APK 之间调用,但这依赖于可以实例化的类.如果要重复使用,您可以将抽象类拆分为一个 Android 库项目 - Android 库项目本质上是共享源,而不是传统的 Java jar.

If by 'package' you mean APK, then yes, the abstract base should be in there with the regular code, as although it is possible to call between APKs, you this relies on classes you can instantiate. You can split the abstract classes out into an Android library project, if they're going to get re-used - Android library projects are essentially shared source, rather than traditional Java jars.

如果您需要有关其中任何一个的更多详细信息,请告诉我,因为这是一个相当广泛的问题,我想保持答案大小可管理

Let me know if you need more details on any of this, as this is quite a broad question, and I'd like to keep the answer size managable

这篇关于清单中的 Android 抽象活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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