Question

Is it safe (or recommended) to call Crittercism.init(getApplicationContext(), id); in both the onCreate of an Application implementation and the MAIN Activity?

The official instructions for Crittercism setup say to call it in the MAIN Activity and don't mention the Application at all.

This seems to have the side effect of ignoring any crashes that happen in the onCreate method of the Application implementation (effectively a singleton). Exceptions there are only reported if init is called in onCreate of the Application implementation.

So is it ok to call init in both, or should it be just the Application, or just the Activity?

Was it helpful?

Solution

It is safe to initialize the Crittercism library in both places, but it's not really necessary. This is because after the first initialization, any subsequent initializations will be detected and ignored.

That leaves you with the option to initialize in either place. Although most people choose to do it at the activity level, starting Crittercism in the Application class does work.

No matter where you initialize the library, crashes and other information should be reported from all of your activities.

OTHER TIPS

Aside from that, if you init Crittercism on an activity-level, any crashes in independently running contentproviders either don't get reported or, if you use Crittercism there to e.g. leave breadcrumbs, crash the contentprovider with the following exception:

Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:121)
at crittercism.android.f$5.<init>(Unknown Source)
at crittercism.android.f.<init>(Unknown Source)
at com.crittercism.app.Crittercism.<clinit>(Unknown Source)

So I would initialize Crittercism always in the Application.onCreate class to avoid those.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top