Code example for FragmentActivity

Methods: getSupportFragmentManager, onKeyDown

0
		case KeyEvent.KEYCODE_BACK:
			if(handleBackKeyEvent()) { 
				return true; 
			} 
		} 
		return super.onKeyDown(keyCode, event);
	} 
	 
	/* 
	 * METHODS 
	 */ 
	 
	public boolean handleBackKeyEvent() { 
		//check if there are no remaining FragmentTransactions in the backstack 
		if(getSupportFragmentManager().getBackStackEntryCount() > 0) { 
			if(DEBUG) Log.d(TAG, "...some remaining backstack entries...");
			getSupportFragmentManager().popBackStack(); 
			return true; 
		} else { 
			if(DEBUG) Log.d(TAG, "...no remaining backstack entries...");
			//pause activity 
			Example01FragmentActivity.this.finish();