我的问题是,我在 TabActivity 的单个选项卡下有多个活动,但问题是如果我从一个活动移动到另一个活动超过 3 次,则会发生“java.lang.StackOverflowError”,对不起我的不好英语交流。
任何帮助,将不胜感激。
我的代码是:-
第一活动.java
public class FirstActivity extends ActivityGroup implements
OnClickListener {
Button mBtnAdd;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.screen1);
mBtnAdd = (Button) findViewById(R.id.mBtnAddManageAccount);
mBtnAdd.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v == mBtnAdd) {
Intent mInSecond = new Intent(v.getContext(), SecondActivity.class);
replaceContentView("SecondActivity", mInSecond);
}
}
public void replaceContentView(String id, Intent newIntent) {
View view = getLocalActivityManager().startActivity(id,
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
this.setContentView(view);
}
}
SecondActivity.java
public class SecondActivity extends ActivityGroup implements
OnClickListener {
Button mBtnBack;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.screen2);
mBtnBack=(Button)findViewById(R.id.mBtnBackNewCustomer);
mBtnBack.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==mBtnBack){
Intent mInBack = new Intent(v.getContext(),
FirstActivity.class);
replaceContentView("FirstActivity", mInBack);
}
}
public void replaceContentView(String id, Intent newIntent) {
View view = getLocalActivityManager().startActivity(id,
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
this.setContentView(view);
}
}
错误日志猫:-
07-19 11:02:01.731: E/AndroidRuntime(528): FATAL EXCEPTION: main
07-19 11:02:01.731: E/AndroidRuntime(528): java.lang.StackOverflowError
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.View.draw(View.java:6986)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.widget.FrameLayout.draw(FrameLayout.java:357)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.widget.ScrollView.draw(ScrollView.java:1409)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.View.draw(View.java:6883)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.widget.FrameLayout.draw(FrameLayout.java:357)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.View.draw(View.java:6883)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.widget.FrameLayout.draw(FrameLayout.java:357)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.View.draw(View.java:6883)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.widget.FrameLayout.draw(FrameLayout.java:357)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.View.draw(View.java:6883)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.widget.FrameLayout.draw(FrameLayout.java:357)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.View.draw(View.java:6883)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.widget.FrameLayout.draw(FrameLayout.java:357)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.View.draw(View.java:6883)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.widget.FrameLayout.draw(FrameLayout.java:357)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.View.draw(View.java:6883)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.widget.FrameLayout.draw(FrameLayout.java:357)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.View.draw(View.java:6883)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.widget.FrameLayout.draw(FrameLayout.java:357)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.View.draw(View.java:6883)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.widget.FrameLayout.draw(FrameLayout.java:357)
07-19 11:02:01.731: E/AndroidRuntime(528): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1862)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewRoot.draw(ViewRoot.java:1522)
07-19 11:02:01.731: E/AndroidRuntime(528): at android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
07-19 11:02:01.731: E/AndroidRuntime(528): a