Home » Android » Android Google Analytics Causing Black Screen

Android Google Analytics Causing Black Screen

Posted by: admin June 15, 2020 Leave a comment


I just followed this tutorial for adding Google Analytics SDK v4 into an android app. Problem now is that when I run the app it just gives a black screen on any view I’ve setup with tracking. For example below the is the onCreate, onStart and onStop methods from the first view after the splash screen. The splash screen loads fine, then I just get a black screen on the view. If you commented out the analytics code everything work

    protected void onCreate(Bundle savedInstanceState) {

        //Get a Tracker (should auto-report)

        //Define font for use
        Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/cabinregular.otf");

        //Set font to all elements
        ((TextView) findViewById(R.id.textFlat)).setTypeface(typeface);
        ((TextView) findViewById(R.id.textCool)).setTypeface(typeface);
        ((TextView) findViewById(R.id.textWarm)).setTypeface(typeface);
        ((TextView) findViewById(R.id.textPastels)).setTypeface(typeface);
        ((TextView) findViewById(R.id.textDecades)).setTypeface(typeface);
        ((TextView) findViewById(R.id.textNeutrals)).setTypeface(typeface);
        ((TextView) findViewById(R.id.textMidTones)).setTypeface(typeface);
        //((TextView) findViewById(R.id.appHeaderText)).setTypeface(typeface);

        //Create all the listeners to catch button presses
        ImageButton buttonFlat = (ImageButton) findViewById(R.id.buttonFlat);
        ImageButton buttonCool = (ImageButton) findViewById(R.id.buttonCool);
        ImageButton buttonWarm = (ImageButton) findViewById(R.id.buttonWarm);
        ImageButton buttonPastels = (ImageButton) findViewById(R.id.buttonPastels);
        ImageButton buttonDecades = (ImageButton) findViewById(R.id.buttonDecades);
        ImageButton buttonNeutrals = (ImageButton) findViewById(R.id.buttonNeutrals);
        ImageButton buttonMidTones = (ImageButton) findViewById(R.id.buttonMidTones);

        ((colorlibApplicationClass) getApplication()).getTracker(colorlibApplicationClass.TrackerName.APP_TRACKER);


    public void onStart()
        //Get an Analytics tracker to report app starts & uncaught exceptions etc.

    public void onStop()
        //Stop the analytics tracking

Here’s the application class;

package com.exampleapp.colorlib;

        import android.app.Application;

        import com.google.android.gms.analytics.GoogleAnalytics;
        import com.google.android.gms.analytics.Tracker;

        import java.util.HashMap;

public class colorlibApplicationClass extends Application {

    // The following line should be changed to include the correct property id.
    private static final String PROPERTY_ID = "UA-REMOVED-FOR-SECURITY";

    //Logging TAG
    private static final String TAG = "MyApp";

    public static int GENERAL_TRACKER = 0;

    public enum TrackerName {
        APP_TRACKER, // Tracker used only in this app.
        GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
        ECOMMERCE_TRACKER,// Tracker used by all the apps from a company. eg: roll-up tracking.


    HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();

    public colorlibApplicationClass() {

    synchronized Tracker getTracker(TrackerName trackerId) {
        if (!mTrackers.containsKey(trackerId)) {

            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(R.xml.app_tracker)
                    : (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(PROPERTY_ID)
                    : analytics.newTracker(R.xml.ecommerce_tracker);
            mTrackers.put(trackerId, t);

        return mTrackers.get(trackerId);
How to&Answers:

It’s a problem of the last version. Check here for more info.

Meanwhile maybe it’s better to use an older version. This one works fine:

compile ‘com.google.android.gms:play-services:6.1.+’

Edit: Removing the global configuration meta-data from the AndroidManifest worked fine.