我在我的活动的Fragment
中重新创建onNewIntent
时遇到问题:
public class MessageActivity extends NavigationActivity {
private FragmentManager fragmentManager = null;
private MessageFragment fragment = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.fragmentManager = this.getSupportFragmentManager();
this.fragment = (MessageFragment) this.fragmentManager.findFragmentByTag(FragmentTags.MESSAGE.getValue());
if (savedInstanceState == null) {
this.fragment = new MessageFragment();
this.fragmentManager.beginTransaction().replace(R.id.menu_slide_main_content, this.fragment, FragmentTags.MESSAGE.getValue()).commit();
}
}
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
this.setIntent(intent);
this.fragmentManager = this.getSupportFragmentManager();
this.fragment = (MessageFragment) this.fragmentManager.findFragmentByTag(FragmentTags.MESSAGE.getValue());
if(fragment == null) {
this.fragment = new MessageFragment();
}
this.fragmentManager.beginTransaction().replace(R.id.menu_slide_main_content, this.fragment, FragmentTags.MESSAGE.getValue()).commit();
}
}
我尝试重新创建的Fragment
有SlidingTabLayout
和ViewPager
:
public class MessageFragment extends Fragment {
private SlidingTabLayout slidingTabLayout;
private ViewPager viewPager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_message_fragment, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
this.viewPager = (ViewPager) view.findViewById(R.id.messages_pager);
this.viewPager.setId(0x5000);
this.viewPager.setAdapter(new MessagePagerAdapter(this.getActivity(), this.getFragmentManager()));
this.slidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.messages_tab_layout);
this.slidingTabLayout.setViewPager(this.viewPager);
}
}
现在调用onNewIntent
并重新创建Fragment
我的片段中的片段
SlidingTabLayout
是空的,滑动不再起作用。
我该如何解决这个问题?