Reputation: 306
I am trying to implement Google Analytics V4 in Android. I tried following Google doc, also I tried following this tutorial. My MainActivity extents FragmentActivity, I have added the GA lib, xml config files and made the modifications showed in the tutorial.
My problem is in the following line that shows me "Cannot resolve 'AnalyticsSampleApp' symbol" error.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
TrackerName.APP_TRACKER);
I know that I have to change 'MyApplication' and use my own application class name, but how can I find my application class name? How can I register my application class name in my manifest file so I can use it?
I tried this..
...
<application
android:name="my.package.myApplication" //Cannot resolve symbol 'myApplication'
...
Should I implement Google Analytics API in another way since my activity is extending FragmentActivity?
*Sorry if this is a silly question. I am very inexperienced in Android development.
Upvotes: 0
Views: 247
Reputation: 132992
"Cannot resolve 'AnalyticsSampleApp' symbol"
Because AnalyticsSampleApp
you have not created AnalyticsSampleApp class in your application.
Create a class with MyApplication
name and extend Application
class:
public class MyApplication extends Application {
public MyApplication() {
super();
}
.....
}
Declare MyApplication
in AndroidManifest.xml:
<application
android:name="my.package.MyApplication"
....
/>
Now use MyApplication
class name instead of to get Tracker
instance:
Tracker t = ((MyApplication) getActivity().getApplication())
.getTracker(TrackerName.APP_TRACKER);
As provided tutorial link you can follow MyApplication class code to create and initialize GoogleAnalytics
class instace.
Upvotes: 1