我为我的应用程序创建了选项卡小部件。每个活动都有多个子活动。我的主要活动是
package com.example.travelmate;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class TaxiActivity extends ActivityGroup
{
Button taxi_meter_btn1,taxi_meter_btn2;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.taxi_layout);
taxi_meter_btn1 = (Button)findViewById(R.id.meter_bt1);
taxi_meter_btn2 = (Button)findViewById(R.id.meter_bt2);
taxi_meter_btn1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v1)
{
// TODO Auto-generated method stub
Intent activity3Intent = new Intent(v1.getContext(),TaxiMeterActivityMain.class);
replaceContentView1("activity3", activity3Intent);
}
});
taxi_meter_btn2.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v2)
{
// TODO Auto-generated method stub
Intent activity4Intent = new Intent(v2.getContext(),TaxiMeterActivityMain.class);
replaceContentView2("activity3", activity4Intent);
}
});
}
@SuppressWarnings("deprecation")
public void replaceContentView1(String id, Intent newIntent) {
View view = getLocalActivityManager().startActivity(id,
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
this.setContentView(view);
}
public void replaceContentView2(String id, Intent newIntent) {
@SuppressWarnings("deprecation")
View view = getLocalActivityManager().startActivity(id,
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
this.setContentView(view);
}
}
我的子活动是
public class TaxiMeterActivityMain extends ActivityGroup
{
Button end_jour_btn;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.taxi_meter_layout);
end_jour_btn = (Button)findViewById(R.id.end_jour_bt);
end_jour_btn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
Intent activity3Intent = new Intent(TaxiMeterActivityMain.this, TaxiActivity.class);
replaceContentView("activity3", activity3Intent);
}
});
}
@SuppressWarnings("deprecation")
public void replaceContentView(String id, Intent newIntent) {
View view = getLocalActivityManager().startActivity(id,
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
this.setContentView(view);
}
}
我想为两个不同的按钮调用这个子活动两次。当我单击第一个按钮时,我可以返回主要活动。但是,当单击相同活动的第二个按钮时,它会引发类似http://pastie.org/8420928的错误。我该如何解决这个问题有人可以帮助我吗?预先感谢。