What is the command to return to your main screen in an app?
How do I have an app re开发者_如何学Goturn to the 'Home' screen when the user is on a different class and they click the back/return button on their phone?
Right now, when they access a different class and hit the back button, it goes back to the Home screen on the Droid rather than the Home screen on the app - how do I get it to go back to the Home Screen on the app?
Thanks!
Use OnBackPressed() method of Activity class. Make conditions like :
public void onBackPressed(){
if(conditon)
{
detailInfoList.setVisibility(View.VISIBLE);//or anything that you want to show
}
}
you can't,
the home button is the only you can't prevent form closing your app. Its done so that you can't block the user inside your applications (like a virus).
the other keys like back menu and research are possible
in your activity
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
if(keyCode == 82){
Log.i("jason","released on menu");
//change view
//return so that the other behavior (leaving the activity) is not tirggered
return false;
}
}
Log.i("jason","actual key code "+keyCode);
return super.onKeyDown(keyCode, event);
}
精彩评论