gpt4 book ai didi

android - 找不到索引为 -1 的 Activity fragment

转载 作者:行者123 更新时间:2023-11-29 01:04:00 26 4
gpt4 key购买 nike

Activity fragment 管理器问题当改变方向时:

Caused by: java.lang.IllegalStateException: Could not find active fragment with index -1
at

android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:3026) at android.support.v4.app.Fragment.restoreChildFragmentState(Fragment.java:1446) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1380) at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740) at com.motors.mobile.core.v2.DaggerIncludeBaseActivity.onCreate(DaggerIncludeBaseActivity.java:26)

按照我的代码:

@Override
protected void tabletPortraitInit(Bundle savedInstanceState) {
super.tabletPortraitInit(savedInstanceState);
openSubFragment();
}

@Override
protected void tableLandscapeInit(Bundle savedInstanceState) {
super.tableLandscapeInit(savedInstanceState);
openSubFragment();
}

protected void openSubFragment() {
Bundle bundle = getIntent().getBundleExtra(CAR_DETAIL_KEY);
fragment = new BuyDetailFragment();
if (getSupportFragmentManager().findFragmentByTag(BuyDetailFragment.TAG) != null)
fragment = (BuyDetailFragment) getSupportFragmentManager().findFragmentByTag(BuyDetailFragment.TAG);
fragment.setArguments(bundle);
menuClickListener = fragment;
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.flMain, fragment, BuyDetailFragment.TAG)
.commit();
// init toolbar items
View tbView = getLayoutInflater().inflate(R.layout.items_detail_menu_layout, toolbar.findViewById(R.id.container), true);
phone = tbView.findViewById(R.id.phone);
message = tbView.findViewById(R.id.message);
link = tbView.findViewById(R.id.notifications);
site = tbView.findViewById(R.id.site);
shortlistView = tbView.findViewById(R.id.wishListMenu);
phone.setOnClickListener((e) -> menuClickListener.clickPhone());
message.setOnClickListener((e) -> menuClickListener.clickMessage());
link.setOnClickListener((e) -> menuClickListener.clickNotifications());
site.setOnClickListener((e) -> menuClickListener.clickSite());
shortlistView.setOnClickListener((e) -> menuClickListener.clickShortlist());
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.vector_heart);
drawable.setColorFilter(ContextCompat.getColor(this, R.color.colorAccent), PorterDuff.Mode.SRC_IN);
shortlistView.changeIcon(drawable);
}

There is no my baseActivity

最佳答案

你的 fragment 有setRetainInstance(true)吗?如果是这样,这可能会给您带来问题,尤其是当您使用 FragmentStatePagerAdapter 的 fragment 时。

关于android - 找不到索引为 -1 的 Activity fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48931474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com