Activity跳转到嵌套的Fragment

背景

MainActivity有四个fragmenet,就叫A,B,C,D吧,在A中还有两个Fragment就叫N,T吧,在C中,点击了某个按钮跳转到了EActivity,在EActivity中进行了一系列操作之后进行提交操作,并且跳转到T。

从C->EActivity的操作过程

1
2
Intent intent = new Intent(getContext(),EActivity.class);
startActivity(intent);

从EActivity->T的操作过程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 先是从EActivity跳转到MainActivity,并且给MainActivity传递一个值,告诉他应该显示A
Intent intent = new Intent(DetailActivity.this, MainActivity.class);
Intent.putExtra("id", 2);
startActivity(intent);

然后在MainActivity中接受从EActivity传来的值,并且显示A,然后MainActivity向A传递一个值,告诉A应该显示T
@Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
int id = intent.getIntExtra("id", 0);
if(id == 2){
CalendarFragment fragment = new CalendarFragment();
Bundle bundle = new Bundle();
bundle.putInt("page", 1);
fragment.setArguments(bundle);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragmnet_main, fragment)
.addToBackStack(null)
.commit();

}
}

A接收到MainActivity传递过来的值,并且设置显示T
@Override
public void onResume() {
super.onResume();
Bundle bundle = this.getArguments();
int page = 0;
if(bundle != null){
page = bundle.getInt("page", 0);
//viewPager.setCurrentItem(page);
slidingTabLayout.setCurrentTab(page);
}
}