Acra: install, extend Application - Activity?
Asked Answered
P

3

6

I am trying to install the ACRA crash report system to my android project. Now, my project is already extending a class, the Activity class. How can I implement the Acra project then?

As they state in normal way, you have to make a class f.e. MyApplication and extend it with Application. Since I am already extending the Activity class I am not sure what to do... They say: If your app already contains an Application subclass, add ACRA to this class; however, I don't know how I should do this..

Thanks!

http://code.google.com/p/acra/wiki/BasicSetup

Pablo answered 11/9, 2012 at 8:29 Comment(0)
H
2

Just create a MyApplication class that extends from Application, do what they say about overriding onCreate() and then go to your AndroidManifest.

You should have an <application> with values such as android:label or android:theme. Just add android:name=".MyApplication" there and you're ready to go.

Have in mind that if your package is com.example.test, MyApplication has to be there. If you want to put MyApplication wherever else, you must point to where it is.

For example, if your package is com.example.test and MyApplication is in com.example.test.application, you must add android:name=".application.MyApplication to your manifest. I strongly reccomend you to use a package just for your Application, as it atomizes your project and makes it far more manageable and mantainable.

Has answered 11/9, 2012 at 8:40 Comment(2)
Well I did just that and the first thing I notice is that my app isnt working anymore... :s 09-11 11:00:36.682: W/dalvikvm(6090): threadid=1: thread exiting with uncaught exception (group=0x4001d560) 09-11 11:00:36.682: E/ACRA(6090): ACRA caught a RuntimeException exception for com.droid. Building report.Pablo
Is there a "Caused by: ...." with another nested exception in the stacktrace ? This should give you an idea of what went wrong.Roband
B
1

Application is used because of the manifest. In the manifest, it is just to add this to the application tag(with all activities inside):

android:name=".MyApplication"

Ex:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:name=".MyApplication"
    android:theme="@style/AppTheme" >

Because of the easy initialization(as it is automatically initialized by the Android System on launch) it will never not report. It can crash instantly on startup and still report. So it is a really smart setup.

My application class looks like this:

@ReportsCrashes(

    formUri = "https://backend.com",
    customReportContent = { /* */ReportField.APP_VERSION_NAME, ReportField.PACKAGE_NAME,ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL,ReportField.LOGCAT },
    mode = ReportingInteractionMode.TOAST,
    resToastText = R.string.crash_toast_text

)  

public class ACRAHandler extends Application {


    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);


        final ACRAConfiguration config = new ConfigurationBuilder(this)

                .build();
        // Initialise ACRA
        ACRA.init(this, config);

    }



}

If you for an instance are using Firebase, you can use both together in the same application-extending class without any issues. I tried it myself and it worked, no problems with error reporting or Firebase.

Additionally, the new links for ACRA is now on Github: https://github.com/ACRA/acra/wiki/BasicSetup

I answered this because it was so long ago the answers came and it needs an update

Blackpool answered 15/7, 2016 at 13:59 Comment(0)
M
-1

An application sub class is required to maintain a global application state, it is not necessary for every app to sub class it. If you app does not have one yet, you can create it.

Example:

/* do ACRA imports */
@ReportsCrashes(formKey = "x-x-x-x-x-x")
public class YourApplication extends Application{

public void onCreate(){
    ACRA.init(this);
    super.onCreate();
}
}

you should also declare in the manifest file as stated in the tutorial.

Magistery answered 11/9, 2012 at 8:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.