我为我的应用程序创建了tab小部件。每个活动都有多个子活动。我的主要活动是
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。我怎么能解决这个问题,有人可以帮助我吗?提前谢谢。