什么是“点"?用于注册活动时 [英] What's the "dot" for when registering an Activity
问题描述
我对 Android 操作系统编程有点菜鸟.我注意到在我读过的书中,作者在清单中注册他们的活动时在活动名称前放置了一个点".我环顾了 Android 开发人员网站,但不明白为什么我们需要点".点"实际上是否有目的?我需要吗?我在下面包含了一个例子.注意NewActivity"之前的点":
I'm kind of a noob at programming for the Android OS. I noticed in the books I have been reading that the authors have placed a "dot" in front of the activity name when registering their activities in the manifest. I've looked around the Android developer site and I can't figure out why we need the "dot". Does the "dot" actually server a purpose? Do I need it? I have included an example below. Notice the "dot" before "NewActivity":
<activity android:name=".NewActivity"></activity>
推荐答案
正如您所注意到的,这一点不是必需的,但它基本上意味着:活动类位于应用程序的同一个包中.因此,如果您的应用程序包是:com.my.package
那么:
As you have noticed the point is not necessary but it basically means: the activity class lives in the same package of the app. So, if your app package is: com.my.package
then:
.YourActivity
表示您的类在com.my.package
内.YourActivity
表示你的类在com.my.package
内(同上)..activities.YourActivity
表示您的课程在com.my.package.activities
内.- 您甚至可以执行以下操作:
com.my.package.activities.YourActivity
当您希望拥有不同版本的应用程序并使用 Ant 自动更改对包的引用时,这很有用.
.YourActivity
means that your class is insidecom.my.package
.YourActivity
means that your class is insidecom.my.package
(same as above)..activities.YourActivity
means that your class is insidecom.my.package.activitites
.- You can even do something like:
com.my.package.activities.YourActivity
which is useful when you want to have different versions of your app and use Ant to change the references to the package automatically.
这篇关于什么是“点"?用于注册活动时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!