I have an application in android that includes a application home page. I override the hardware Home button to go back to the application home page for API level 10 or less.
My application works fine on Android version 3.0 and 4.0. The problem is overriding the Home button. I found a discussion ( Disable Home Button in Android ICS (4.0) ) which includes a method to implement a home screen somehow. It is suggested by @Chalaman.
I did not get the point yet. Is there any one that can help me more by providing some codes?
when we use :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
in the manifest file, a dialog pops up when we click on the home button. It includes the home phone page icon and application icon. we can make a choice. If we select the application icon, we stay in the application. The problem is we stay also in the same activity. How can I go to another activity (home page of my application)?
We can to it in API level 10 or less:
@Override
public void onAttachedToWindow() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_HOME:
loadStartPage();
break;
}
return super.onKeyDown(keyCode, event);
}
private void loadStartPage() {
Intent intent = new Intent(getApplicationContext(), StartActivity.class);
intent.putExtra("user", user);
intent.putExtra("user_id", user_id);
intent.putExtra("server", server);
intent.putExtra("password", password);
main_activity.startActivity(intent);
}
How to Load Start Page in API level 11 or greater?