I recently started adding Google Analytics integration into my Application. To do so I've been following the steps provided here: https://developers.google.com/analytics/devguides/collection/android/v4/
I had no Application class so I created one with the basic implementation provided here: http://www.javacodegeeks.com/2014/04/working-with-google-analytics-api-v4-for-android.html
In each Activity I added the following snippets:
@Override
protected void onStart() {
super.onStart();
//Get an Analytics tracker to report app starts & uncaught exceptions etc.
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
protected void onStop() {
super.onStop();
//Stop the analytics tracking
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Get a Tracker (should auto-report)
((MyApplication) getApplication()).getTracker(MyApplication.TrackerName.APP_TRACKER);
//...
}
and I started seeing live users on my corresponding Analytics page.
For whatever reason when I start the App via fresh install from Android Studio it works fine. However when I kill the app through the task manager and start it again it displays only a blank screen and provides the following error.
E/Trace﹕ error opening trace file: No such file or directory (2)
D/ActivityThread﹕ setTargetHeapUtilization:0.25
D/ActivityThread﹕ setTargetHeapIdealFree:8388608
D/ActivityThread﹕ setTargetHeapConcurrentStart:2097152
W/dalvikvm﹕ VFY: unable to resolve virtual method 36489: Ljava/lang/ReflectiveOperationException;.printStackTrace ()V
W/dalvikvm﹕ VFY: unable to resolve virtual method 11845: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
W/dalvikvm﹕ VFY: unable to resolve virtual method 11842: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
W/dalvikvm﹕ VFY: unable to resolve virtual method 11848: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
W/dalvikvm﹕ VFY: unable to resolve virtual method 9471: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
W/dalvikvm﹕ VFY: unable to resolve virtual method 565: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
W/dalvikvm﹕ VFY: unable to resolve virtual method 587: Landroid/content/res/TypedArray;.getType (I)I
I feel like I'm missing something super basic here. Can anyone point me in the right direction?
I looked through some of the related issues on Stack Overflow and it doesn't look like any cover my current case.
I'm using play services version 65870000
and have the following two lines added to my manifest:
<!--This meta-data tag is required to use Google Play Services.-->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- Google Analytics Version v4 needs this value for easy tracking -->
<meta-data
android:name="com.google.android.gms.analytics.globalConfigResource"
android:resource="@xml/global_tracker" />
My current test device is a LG Lucid 2 (vs870) running Android 4.1.2
If there's any other code snippets I should include, please feel free to ask.
Note: I checked out my previous tag and this issue is not present so it must be related to creating this Application class, src/main/res/xml/app_tracker.xml
and src/main/res/xml/global_tracker.xml
config files and adding required analytics setup code in activities.
Thanks in advance for any help or suggestions!
Edit: If I remove the following lines from my MainActivity the app starts up properly every time again:
// onStart
GoogleAnalytics.getInstance(this).reportActivityStart(this);
// onStop
GoogleAnalytics.getInstance(this).reportActivityStop(this);
// onCreate
((MyApplication) getApplication()).getTracker(MyApplication.TrackerName.APP_TRACKER);