Android 在清单中注册应用程序类?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2929562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Register Application class in Manifest?
提问by Sharj
I have one Application class to keep the global state of my application. But I'm unable to register it in Manifest file? Any idea how to do this?
我有一个 Application 类来保持我的应用程序的全局状态。但是我无法在 Manifest 文件中注册它?知道如何做到这一点吗?
回答by Rich
If it derives from Application, add the fully qualified (namespace + class name) as the android:name
parameter of the application element in your manifest.
如果它派生自 Application,请android:name
在清单中添加完全限定的(命名空间 + 类名)作为application 元素的参数。
<application
android:name="com.you.yourapp.ApplicationEx"
Or if the class' package can be described as relative to the package
in the manifest
tag, then just start with a .
:
或者,如果类的包可谓是相对package
的manifest
标签,那么就先从.
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.you.yourapp">
<application
android:name=".ApplicationEx"
回答by Bawa
but in case you are already using some library like branch.io's library then most probably your manifest
但是如果您已经在使用诸如 branch.io 的库之类的库,那么很可能是您的清单
<application name="">
<application name="">
property will already have some name like
属性已经有一些名称,如
`<application name="io.referral.BranchApp">
in that case you need to first extend your application class, like below:
在这种情况下,您需要首先扩展您的应用程序类,如下所示:
public class Application extends BranchApp
and then register your application in manifest as:
然后在清单中将您的应用程序注册为:
android:name="absdevelopers.com.brankreferal.Application"
this works perfectly for me :) i hope it helps someone in trouble :)
这对我来说非常有效:) 我希望它可以帮助遇到麻烦的人 :)
回答by Anos K. Mhazo
If you are using a MultiDex application you will already have "android:name" in use so instead extend android.support.multidex.MultiDexApplication
:
如果您使用的是 MultiDex 应用程序,您将已经使用了“android:name”,因此请改为扩展android.support.multidex.MultiDexApplication
:
public class MyApplication extends MultiDexApplication {...}
And add it to the Android manifest:
并将其添加到 Android 清单中:
android:name="app.package.MyApplication"