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
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.
I have posted a detailed tutorial. This lets you go through setting up ACRA for existing project and configure it to send an email to your email address. Link
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With