Code example for Fragment

Methods: getActivity, onPause

0
	@Override 
	public void onPause() { 
		/* 
		 * Set pref so LogService can send log lines to the broadcastreceiver 
		 */ 
		if (getActivity() != null)
			PrefUtil.writeBoolean(this.getActivity(), HAS_LOGFRAGMENT, false);
		unregisterReceiver(); 
		super.onPause(); 
	} 
 
	@Override 
	public void onResume() { 
		if (getActivity() != null) {
			PrefUtil.writeBoolean(this.getActivity(), HAS_LOGFRAGMENT, true);
			logToggle.setChecked(PrefUtil.readBoolean(this.getActivity(),
					Pref.LOG_KEY.name())); 
			registerReceiver(); 
			setIcon(); 
		} 
		mySV.post(new ScrollToBottom());
		super.onResume(); 
	} 
 
	public static LogFragment newInstance(Bundle bundle) {
		LogFragment f = new LogFragment();
		f.setArguments(bundle);
		return f;
	} 
 
	public void registerReceiver() { 
		IntentFilter filter = new IntentFilter(LOG_MESSAGE_INTENT);
		BroadcastHelper.registerReceiver(getActivity(), receiver, filter, true);
	} 
 
	public void unregisterReceiver() { 
		BroadcastHelper.unregisterReceiver(getActivity(), receiver);
	} 
}