Code example for Fragment

Methods: onDetach

0
	public static class TrackerFragment extends Fragment {
		public GoogleAnalyticsTracker tracker;
		 
		@Override 
		public void onDetach() { 
			super.onDetach(); 
			Analytics.stop(tracker);
		} 
		 
		public TrackerFragment() {} 
	} 
	 
	// simple convenience function for when a fragment wants to log a URL 
	// don't need to worry about making sure it only happens once, because Fragments manage their own state 
	// in a way that activities do not. 
	public static void track(Fragment fragment, String url) {
		if (fragment.isAdded()) {
			GoogleAnalyticsTracker tracker = start(fragment.getActivity());
			page(fragment.getActivity(), tracker, url);
			stop(tracker);
		}