Permanent Activity as "home"
Is there a way to keep an application's main activity always alive in the foreground? I mean, the Home key or the Back key disabled.
The applica开发者_运维问答tion will be used by ordinary users and administrators. The idea is that only the administrator can, from an internal activity of the application, access the rest of the system.
I have read that there is no way to override Home key, so any confirmation/workaround would be appreciated.
Sounds like the easiest way would be to create a Home replacement.
Override the OnKeyDown of an Activity where you can capture all key events,check if home or back back pressed if that pressed return as true. it wont propagate event.
Here is the example To prevent the back key in android
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ( Integer.valueOf(android.os.Build.VERSION.SDK) < 7 //Instead use android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
&& keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0) {
// Take care of calling this method on earlier versions of
// the platform where it doesn't exist.
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
return;
}
精彩评论