Android ==> disable multi tasking?
1- How can i disable multi tasking? My application is a socket based game, every time i start the app, it MUST load the main page first to start the socket connection? I do not want the user to be able to run my application in background. Is this possible to do?
2- I do not want the user to be able to use the back button, to navigate between pages, users must only use the buttons available in my application to 开发者_如何学Gonavigate? is this possible?
You can catch the back button (and ignore it), but you cannot block the Home button.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
return true;
}
...
Remember, the Phone is just another application so this OS design prevents a rogue application from disabling the "phone" aspect of the device.
If you want to prevent your application from running in the background, you can close the activity from within the onPause() method:
@Override
protected void onPause()
{
super.onPause();
finish();
}
This will force your application to start from scratch if it is put into the background for any reason. This will probably be called when the phone is put to sleep, however, so it might not be the exact behavior you are looking for.
精彩评论