Problems Using Google Analytic in Android in the application class

For a while now you have been able to use Google Analytics to track user Analytics in Android applications.  Its pretty simple to use, but I found one bug that other people may run in to.  The application I’m working on has its static application data stored in a custom instance that implements the Android application class.  When I first started working with Analytics I placed the tracker in the application class, and had the tracker start during the constructor of the application.  This didn’t work at all, as the tracker.startNewSession would throw null pointer exceptions try to create a database.

Lucky for me, all my activities extend a custom activity, so I could add the tracker there.  At first I wasn’t too happy to have an instance of the tracker per activity, but it turns out that getInstance() function is actually getting an instance of a static class, so in reality there is only one instance of the tracker in memory.

Hope this helps someone getting started with Google Analytics in Android.

-James

Tuesday, July 17th, 2012 Android, Programming

Leave a Reply


Native or HTML5?

View Results

Loading ... Loading ...