我也堅持了這個問題,但解決它看看下面的代碼的希望將幫助您還
你的ActivityGroup應該是這樣的
public class ABCGroup extends ActivityGroup{
public static ABCGroup group;
private ArrayList<View> history;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.history = new ArrayList<View>();
group = this;
View view = getLocalActivityManager().startActivity
("ParentActivity",
new Intent(this, ParentActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
replaceView(view);
}
public void replaceView(View v) {
// Adds the old one to history
history.add(v);
// Changes this Groups View to the new View.
setContentView(v);
}
public void back() {
if(history.size() > 0) {
history.remove(history.size()-1);
if(history.size()<=0){
finish();
}else{
setContentView(history.get(history.size()-1));
}
}else {
finish();
}
}
@Override
public void onBackPressed() {
ABCGroup.group.back();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_BACK){
ABCGroup.group.back();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
在你父活動
View mview = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)).getDecorView();
ABCGroup.group.replaceView(v);
在你的孩子的活動使用
public boolean onKeyDown(int keyCode, KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_BACK){
ABCGroup.group.back();
return true;
}
return super.onKeyDown(keyCode, event);
}
非常感謝你的好友 –
@Nirav:最歡迎的:) –
先生您好...即時使用code..and它完美works..my問題是當我按回來按鈕我的活動組的第一個視圖不顯示。 –