Realm保留一个已删除的对象

问题描述 投票:0回答:1

我有两个片段A和B,在片段BI中使用事务删除一个对象然后我执行getActivity().getSupportFragmentManager().popBackStack();返回片段A,删除对象后我调试并发现该对象被正确删除,但是当我返回片段AI时发现它,这很奇怪!

这是我的片段A中的代码

realm.executeTransactionAsync(new Realm.Transaction() {
                                    @Override
                                    public void execute(@NonNull Realm realm) {
                                        Infraction infraction = realm.where(Infraction.class).equalTo("id",id_new_inf).findFirst();
                                        if(infraction != null)
                                            infraction.deleteFromRealm();
                                    }
                            });
  getActivity().getSupportFragmentManager().popBackStack();

那么为什么对象没有被删除?

在片段A中,我没有什么特别的东西,它只是onCreateView中的一个请求

@Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        final View v = inflater.inflate(R.layout.list_infractions, container, false);
infractions = realm.where(Infraction.class).findAll();
}
android android-fragments realm
1个回答
0
投票

realm.executeTransactionAsync((r) ->
                    Infraction infraction = r.where(Infraction.class).equalTo("id",id_new_inf).findFirst();
                    if(infraction != null)
                          infraction.deleteFromRealm();
                    }
             }, () -> { // on Success 
                    getActivity().getSupportFragmentManager()
                                .popBackStack();
             });
© www.soinside.com 2019 - 2024. All rights reserved.