我们如何跳过android中的活动?
我有4项活动,从活动A 我需要转到活动C 。有可能吗?
第一个流程: Activity A
- Activity B
- Activity C
- Activity D
第二个流程: Activity A
- Activity B
- Activity D
//跳过活动C < / p>
答案 0 :(得分:0)
您必须startActivity()
根据您的条件决定打开哪个活动。请参阅下面的伪代码:
if(condition == "B"){
Intent toActivityB = new Intent(this,ActivityB.class)
startActivity(toActivityB)
} else {
Intent toActivityC = new Intent(this,ActivityC.class)
startActivity(toActivityC)
}
答案 1 :(得分:0)
你的流程是这样的:
第一个流程: SomeActivity - &gt; CreateCustomer - &gt; ShopActivity - &gt; AddressActivity
第二个流程: AddCustomer - &gt; CreateCustomer - &gt; AddressActivity
尝试使用以下代码:仅对第二个流程执行此操作,发送source
以跳过活动。
AddCustomer 类:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_customer);
//inside click listner
Intent i = new Intent(AddCustomer.this,CreateCustomer.class);
i.putExtra("SOURCE", "ADD_CUSTOMER");
startActivity(i);
}
CreateCustomer 类:此处只需要发货ShopActivity
String source = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_customer);
//if source will be AddCustomer it will skip ShopActivity
if(getIntent().getExtras()!=null)
{
source = getIntent().getExtras().getString("SOURCE");
}
//inside click listner
if(source.equals("ADD_CUSTOMER"))
{
Intent i = new Intent(CreateCustomer.this,AddressActivity.class);
startActivity(i);
}else{
Intent i = new Intent(CreateCustomer.this,ShopActivity.class);
startActivity(i);
}
}