扩展Android Application类

Siv*_*a K 8 android extends class constants

当我在寻找从远程设备获取错误报告的解决方案时,就像iOS中的测试飞行应用程序一样,我在这里找到了acra针对Android的设备

在基本设置中,他们说我们需要添加一些内容extends Application class.

到目前为止,在我的项目中,我没有创建这样的课程,当我在SO中搜索这个时,我提出了几个关于这个问题的问题extends Application class.

我明白他们说的是包含全局变量的Constant类,我是否理解正确的方法.

在我的项目,我用它来创建一个命名为类Constants,其中包含了一些global variablesStrings, int, ArrayList我这个班我用做我的api hitsjson parsings.这个类可以用作extends Application.

如果它是相同的,在上面提到的链接,他们说

override the onCreate() method to add the ACRA init statement 
Run Code Online (Sandbox Code Playgroud)

但到目前为止,我还没有onCreate在我的Constant类中创建一个方法.我做对了吗?

Dav*_*ser 20

我不打算尝试将你的Constants课程与这门课程合并.这不值得努力.只需创建一个新类,它可以完成ACRA所需的操作.像这样:

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        // do the ACRA init here
    }
}
Run Code Online (Sandbox Code Playgroud)

现在你需要确保你的MyApplication类被使用了.因此,您需要像清单一样添加android:name<application>清单中的标记条目

<application
    android:name="fully.qualified.package.name.MyApplication"
Run Code Online (Sandbox Code Playgroud)

完成.