У меня проблема с FragmentManager is already executing transactions
. Я исследую, как решить эту проблему, но ответы не те, что у меня есть в моих кодах. Они используют viewpager и менеджер фрагментов, но я использую транзакцию фрагмента только потому, что я использую нижнюю панель навигации.
Основной причиной является прослушиватель снимка с домашнего фрагмента. Может кто-нибудь помочь мне исправить это? Вот мой код:
MainActivity.java
final Intent intent = getIntent();
final String UserID = intent.getStringExtra("userid");
final HomeFragment fragment = new HomeFragment();
Bundle bundleh = new Bundle();
bundleh.putString("userid", UserID);
fragment.setArguments(bundleh);
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commitNow();
А вот строка, на которую указывает ошибка
HomeFragment.java
db.collection("Baskets").document(uid).collection("Store_Baskets")
.addSnapshotListener(getActivity(), new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
if (e != null){
Log.e(LOG_DB, e.toString());
}else {
List<String> ids = null;
for (DocumentSnapshot ds: queryDocumentSnapshots){
ids.add(ds.getId());
}
if (ids.size()==0){
basket_count.setText("0");
}else {
basket_count.setText(String.valueOf(ids.size()));
}
}
}
});
Stacktrace
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dreamakers.coonna/com.dreamakers.coonna.Activity.HomeBuyersActivity}: java.lang.IllegalStateException: FragmentManager is already executing transactions
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2608)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Caused by: java.lang.IllegalStateException: FragmentManager is already executing transactions
at androidx.fragment.app.FragmentManagerImpl.ensureExecReady(FragmentManager.java:2207)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2267)
at androidx.fragment.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:814)
at com.google.firebase.firestore.core.ActivityScope.lambda$onFragmentActivityStopCallOnce$1(com.google.firebase:firebase-firestore@@21.1.1:180)
at com.google.firebase.firestore.core.ActivityScope$$Lambda$2.run(com.google.firebase:firebase-firestore@@21.1.1)
at android.app.Activity.runOnUiThread(Activity.java:5384)
at com.google.firebase.firestore.core.ActivityScope.onFragmentActivityStopCallOnce(com.google.firebase:firebase-firestore@@21.1.1:164)
at com.google.firebase.firestore.core.ActivityScope.bind(com.google.firebase:firebase-firestore@@21.1.1:192)
at com.google.firebase.firestore.Query.addSnapshotListenerInternal(com.google.firebase:firebase-firestore@@21.1.1:1035)
at com.google.firebase.firestore.Query.addSnapshotListener(com.google.firebase:firebase-firestore@@21.1.1:995)
at com.google.firebase.firestore.Query.addSnapshotListener(com.google.firebase:firebase-firestore@@21.1.1:939)
at com.dreamakers.coonna.Activity.HomeFragment.onCreateView(HomeFragment.java:166)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273)
at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1244)
at android.app.Activity.performStart(Activity.java:6108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2491)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2608)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)