Activitygroup Not Handling Back Key For Listactivity
Solution 1:
In a ActivityGroup, When ListActivity is in focus onKeyDown() of ActivityGroup is not getting called, only child's (ListActivity) onKeyDown() is getting called To make sure ActivityGroup's onKeyDown() is called, We need to return false from onKeyDown() of ListActivity. After doing this change I am able to receive key events
Solution 2:
I know what you mean... I faced that problem some weeks ago. I also know it's an annoying bug and I've learned the lesson: I won't use that approach ever! So, basically, in order to fix this you will have to do some workarounds to your code. For instance, I fixed that problem with one of my activities adding this code to the activity:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && StatsGroupActivity.self != null) {
StatsGroupActivity.self.popView();
returntrue;
}
return super.onKeyDown(keyCode, event);
}
Notice that my ActivityGroup
is called StatsGroupActivity
and looks like:
publicclassStatsGroupActivityextendsGroupActivity{
/**
* Self reference to this group activity
*/publicstatic StatsGroupActivity self;
publicvoidonCreate(Bundle icicle){
super.onCreate(icicle);
self = this;
// more stuff
}
}
Solution 3:
@Cristian
I am using a normal Activity instead of ListActivity, but with a ListView populated it gave me the same problem.
I only implemented onBackPressed on my Activity instead of onKeyDown to call back the same back() function that MyActivityGroup invoked.
@Override
publicvoidonBackPressed() {
MyActivityGroup.group.back();
return;
}
group is a static field in MyActivityGroup.
publicstatic MyActivityGroup group;
The back() function would be the same as yann.debonnel provided.
I don't know if this is the same case for your ListActivity, didn't test it. But in my case it worked.
Post a Comment for "Activitygroup Not Handling Back Key For Listactivity"