列出包中的活动
我开始编写一个 Android 应用程序,它将作为参考实用程序。
目前,我正在将活动组织到包中,因此我想编写一个类,将包中的活动列出到视图中以建立层次结构。
我不知道如何向包裹询问该信息。
关于如何实现这一目标有什么想法吗?更好的应用程序设计的技巧?
谢谢。
I am starting to write an Android application that is going to be a reference utility.
As of the moment I am organizing the activities into packages so I would like to write a class that will list the activities in the package to the view to establish the hierarchy.
I do not know know how to ask a package for that information.
Any ideas of how to accomplish this? Tips for a better application design?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您查看 PackageManager 文档,它非常简单。
以下是大致步骤:
使用 Context.getPackageManager() 获取
PackageManager
的实例。然后对所需的包调用
PackageManager.getPackageInfo()
。这将返回一个ApplicationInfo
对象,该对象具有公共成员ApplicationInfo.ActivityInfo
。ActivityInfo
是AndroidManifest.xml
文件中所有
标记的数组。如果不清楚,请阅读 PackageManager 文档,然后按照链接,直到到达 PackageInfo
Its pretty straight forward if you look at the PackageManager Docs.
Here are the rough steps:
Use
Context.getPackageManager()
to get an instance ofPackageManager
.Then call
PackageManager.getPackageInfo()
on the desire package. That will return anApplicationInfo
object which has a public memberApplicationInfo.ActivityInfo
.ActivityInfo
is an array of all the<activity>
tags from theAndroidManifest.xml
file.If this isn't clear read the PackageManager docs and then follow the links until you get to PackageInfo
另一种方法是使用元数据创建 XML 文件。我希望它对您有所帮助,因为您可以轻松访问。
Another way is to create an XML file with your metadata. I hope it's helpful because you can access easily.