I have an activity, say FirstActivity, and multiple views that are utilized by it. Views are switched by clicking buttons on screen. Currently, I handle back button (to return to previous view) this way:
@Override
public boolean onKeyDown (int keyCode,KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (current == ViewNum.VIEW_DEFAULT) {
return super.onKeyDown(keyCode,event);
}
else {
setContentView(R.layout.firstactivitynew);
configureUI();
return true;
}
}
else {
return super.onKeyDown(keyCode,event);
}
}
}
This, obviously, works only if I have one nested contentView, and this is a case. However, I have a feel that there is something terribly wrong with this way of handling this. Is there any 'standard' way to handle this?
0 comments:
Post a Comment