AndroidResideMenu
AndroidResideMenu copied to clipboard
Handling Configuration Changes
Hi, Is it possible to add support for Handling Configuration Changes ? Or at least could you please provide guidance to handling configuration changes for ResideMenu?
Thank you.
Hello, @csava . I have a simple solution to handle configuration changes. And I have pushed it to the dev branch.
1 For AndroidResideMenu, I added two overload methods. They provide a same parameter named withAnimations
, you can open/close menu without animations by passing it false
.
public void openMenu(int direction, boolean withAnimations);
public void closeMenu(boolean withAnimations);
2 For activity, I suggest to use onSaveInstanceState()
to save the current opening state and direction of menu. Then, it will pass saved instance state to onCreate()
after configurations changed.
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (resideMenu != null) {
outState.putBoolean(MENU_STATE, resideMenu.isOpened());
outState.putInt(MENU_DIRECTION, resideMenu.getCurrentDirection());
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
....
// Restore the menu state by savedInstanceState.
if ( savedInstanceState != null && savedInstanceState.getBoolean(MENU_STATE) == true ) {
resideMenu.openMenu(savedInstanceState.getInt(MENU_DIRECTION));
}
}
If it works, please comment on here and I will merge code into master. Thanks.
Hi ,
Thanks for your answer.
Your answer should work when the developer does not require manually handling of the configuration changes.
Unfortunately, my issue is that I need to manually handle the configuration changes by overriding “onConfigurationChanged” and by putting in the manifest “android:configChanges="keyboard|keyboardHidden|orientation”.
I don't see this issue as a bug but would be a nice enhancement to have it. In many cases android force you to handle the configuration changes manually.
For this case I think residemenu needs an interface like "detachOnCfgChange()" to be used like
@Override public void onConfigurationChanged(Configuration newConfig) {
ResideMenu.detachOnCfgChange()
super.onConfigurationChanged(newConfig);
setContentView(R.layout.main);
// Reinitialize the residemenu
setUpMenu();
}
On this call residemenu can do the clean up or others because the main view will be destroyed.
OK, thanks your idea! I will find someway to implement it.