简体   繁体   English

在清单中注册应用程序类?

[英]Register Application class in Manifest?

I have one Application class to keep the global state of my application.我有一个 Application 类来保持我的应用程序的全局状态。 But I'm unable to register it in Manifest file?但是我无法在 Manifest 文件中注册它? Any idea how to do this?知道如何做到这一点吗?

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
        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 .或者,如果可以将类的包描述为相对于manifest标记中的package ,则只需以. :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.you.yourapp">

    <application
        android:name=".ApplicationEx"

but in case you are already using some library like branch.io's library then most probably your manifest但是如果您已经在使用诸如 branch.io 的库之类的库,那么很可能是您的清单

<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 :)这对我来说非常有效:) 我希望它可以帮助遇到麻烦的人 :)

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"

If the activity is included as a dependency that you can lauch a class this should solve it in 2021.如果该活动作为您可以启动类的依赖项包含在内,这应该会在 2021 年解决。

Add tools:ignore="MissingClass" to your activity element in the Android manfifest filetools:ignore="MissingClass"到 Android 清单文件中的活动元素

example例子

<activity
            android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
            android:screenOrientation="portrait"
            android:theme="@style/LicensesTheme"
            tools:ignore="MissingClass"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM