public class AnalyticsHelper { static final String TAG = "AnalyticsHelper"; GoogleAnalyticsTracker mTracker; private Context mApplicationContext; private static AnalyticsHelper sInstance; /** * Returns the global {@link AnalyticsUtils} singleton object, creating one * if necessary. */ public static AnalyticsHelper getInstance(Context context) { if (sInstance == null && context != null) { sInstance = new AnalyticsHelper(context); } return sInstance; } private AnalyticsHelper(Context context) { if (context == null) { // This should only occur for the empty Analytics utils object. return; } mApplicationContext = context.getApplicationContext(); mTracker = GoogleAnalyticsTracker.getInstance(); mTracker.start("UA-CODE", mApplicationContext); //mTracker.setDebug(true); //mTracker.setDryRun(true); Log.d(TAG, "Initializing Analytics"); } public void trackError(RuntimeException e, String action, String label, String errorMessage, Context context) { trackEvent("exception", action, label, 0); Toast.makeText(context, errorMessage, Toast.LENGTH_SHORT).show(); throw e; } public void trackEvent(final String category, final String action, final String label, final int value) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... voids) { try { mTracker.trackEvent(category, action, label, value); } catch (Exception e) { Log.w(TAG, e.getMessage()); } return null; } }.execute(); } public void trackPageView(final String path) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... voids) { try { mTracker.trackPageView(path); } catch (Exception e) { Log.w(TAG, e.getMessage()); } return null; } }.execute(); } public void dispatch() { //didn't like running as a single thread mTracker.dispatch(); } public void stop() { dispatch(); mTracker.stop(); }}private void updateHandicap(int golferId) { try { AsyncTask.Status status = updateGolferTask.getStatus(); if (AsyncTask.Status.PENDING.equals(status)) { updateGolferTask.execute(new String[]{golferId + ""}); } } catch (Exception e) { AnalyticsHelper.getInstance(this).trackEvent("exception", "updateHandicap", this.getLocalClassName(), 0); }}<?xml version="1.0" encoding="utf-8"?><TableLayout android:layout_width="fill_parent" android:layout_height="50dip" android:stretchColumns="*"> <TableRow> <TextView android:id="@+id/course_item" android:layout_width="140dip" android:layout_height="wrap_content" style="@style/ListsText" android:textColor="@color/title_text"/> <TextView android:id="@+id/teeBox_item" android:layout_width="80dip" android:layout_height="wrap_content" style="@style/ListsText" android:textColor="@color/title_text"/> <TextView android:id="@+id/par_item" android:layout_width="50dip" android:layout_height="wrap_content" style="@style/ListsText" android:textColor="@color/title_text"/> <TextView android:id="@+id/holes_item" android:layout_width="50dip" android:layout_height="wrap_content" style="@style/ListsText" android:textColor="@color/title_text"/> </TableRow></TableLayout>ListView courseListView = (ListView) findViewById(R.id.courseListView);List<Course> courses = courseService.findAll(); final ListAdapter adapter = new CourseAdaptor(this, R.layout.course_item, courses);courseListView.setAdapter(adapter);public class CourseAdaptor extends ArrayAdapter<Course> { private int resource; public CourseAdaptor(Context context, int resource, List<Course> objects) { super(context, resource, objects); this.resource = resource; } @Override public View getView(int position, View convertView, ViewGroup parent) { LinearLayout layout; Course course = getItem(position); String name = course.getName(); String teebox = course.getTeeBox(); String par = course.getPar()+""; String holes = course.getHoles()+""; if (convertView == null) { layout = new LinearLayout(getContext()); String inflater = Context.LAYOUT_INFLATER_SERVICE; LayoutInflater vi = (LayoutInflater)getContext().getSystemService(inflater); vi.inflate(resource, layout, true); } else { layout = (LinearLayout)convertView; } TextView nameView = (TextView)layout.findViewById(R.id.course_item); TextView teeboxView = (TextView)layout.findViewById(R.id.teeBox_item); TextView parView = (TextView)layout.findViewById(R.id.par_item); TextView holesView = (TextView)layout.findViewById(R.id.holes_item); nameView.setText(name); teeboxView.setText(teebox); parView.setText(par); holesView.setText(holes); return layout; }}<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"> <ListView android:id="@+id/courseListView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:cacheColorHint="@color/background2" /></LinearLayout>public void onHomeClick(View v) { tracker.trackEvent("ui_interaction", "onHomeClick", this.getLocalClassName(), 0); if (this instanceof DashboardActivity) { return; } final Intent intent = new Intent(this, DashboardActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); this.startActivity(intent);}public class TrackedActivity extends Activity { protected GoogleAnalyticsTracker tracker; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dashboard); tracker = GoogleAnalyticsTracker.getInstance(); tracker.start("UA-YOUR-ACCOUNT-HERE", this);// tracker.setDebug(true);// tracker.setDryRun(true); } @Override protected void onResume() { super.onResume(); tracker.trackPageView("/" + this.getLocalClassName()); } @Override protected void onDestroy() { super.onDestroy(); tracker.dispatch(); tracker.stop(); }}