问题描述
我使用的是的ActivityGroup产卵多种活动,并从同一选项卡中的TabActivity切换视图。
I am using an ActivityGroup to spawn multiple activities and switch views from within the same tab in a TabActivity.
当我preSS返回键调用此方法在我的ActivityGroup
When I press the back key this method is called inside my ActivityGroup
public void back() {
if(history.size() > 0) {
history.remove(history.size()-1);
if (history.size() > 0)
setContentView(history.get(history.size()-1));
else
initView();
}else {
finish();
}
}
这种方法可以让我保持一叠我的活动,并返回到previous之一,当返回键是pressed。
this method allows me to keep a stack of my activities and go back to the previous one when the back key is pressed.
这是运作良好,在我所有的嵌套的活动,除了在一个ListActivity,其中就回来键preSS将退出该应用程序。
this is working well on all my nested activities, except on a ListActivity where a press on the back key will simply exit the application.
推荐答案
我知道你的意思......我几个星期前面临的问题。我也知道这是一个恼人的错误,我已经吸取了教训:我不会用这种方法永远!所以,基本上,为了解决这个问题,你将不得不做一些变通方法,您的code。举例来说,我固定的问题,我的活动,加入该code到活动之一:
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();
return true;
}
return super.onKeyDown(keyCode, event);
}
请注意,我的的ActivityGroup
叫 StatsGroupActivity
,看起来像:
public class StatsGroupActivity extends GroupActivity{
/**
* Self reference to this group activity
*/
public static StatsGroupActivity self;
public void onCreate(Bundle icicle){
super.onCreate(icicle);
self = this;
// more stuff
}
}
这篇关于的ActivityGroup不处理返回键的ListActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!