0

我正在使用带有可过滤实现的回收器视图。我的代码工作正常。我在视图持有者中有两个按钮,它们将根据 firebase 数据库状态出现。当我单击它们时,更改状态的方法可以正常工作。但是当我第二次在同一个按钮上执行此操作时(记住按钮根据 firebase 状态更改),该方法工作正常,但是当我第三次执行此操作时,我的应用程序获取 struct 并且应用程序无法从 firebase 获取数据。它只是在日志中显示以下内容

I/ple.aadhar_dha: Background concurrent copying GC freed 739900(15MB) AllocSpace objects, 0(0B) LOS objects, 49% free, 22MB/45MB, paused 33us total 102.991ms
I/ple.aadhar_dha: Background concurrent copying GC freed 1279638(26MB) AllocSpace objects, 0(0B) LOS objects, 41% free, 33MB/57MB, paused 67us total 145.459ms
I/ple.aadhar_dha: Background concurrent copying GC freed 1325698(27MB) AllocSpace objects, 0(0B) LOS objects, 34% free, 46MB/70MB, paused 51us total 185.916ms
I/ple.aadhar_dha: Background concurrent copying GC freed 1379285(28MB) AllocSpace objects, 0(0B) LOS objects, 30% free, 55MB/79MB, paused 50us total 193.702ms
I/ple.aadhar_dha: Background concurrent copying GC freed 1389025(28MB) AllocSpace objects, 0(0B) LOS objects, 25% free, 69MB/93MB, paused 33us total 295.979ms

我不知道如何处理这个错误请帮助我

这是我的 User_Status 类

public class User_Status extends AppCompatActivity {

    Toolbar toolbar;
    ProgressBar progressBar;
    private final List<UserHelperClass> mDataList=new ArrayList<>();
    private user_status_adapter user_status_adapter;
    TextInputLayout searchText;
    String search_string;
    SwipeRefreshLayout refreshLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user__status);

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        refreshLayout=findViewById(R.id.refreshLayout_user_control);
        refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

                getUserInformation();
                refreshLayout.setRefreshing(false);
            }
        });

        toolbar = findViewById(R.id.custome_toolbar);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setActionBar(toolbar);
        }

        searchText=findViewById(R.id.textlayout_search_layout_user_control);
        search_string= Objects.requireNonNull(searchText.getEditText()).toString().trim();


        progressBar = (ProgressBar) findViewById(R.id.spin_kit);
        Sprite fadingCircle = new Circle();
        progressBar.setIndeterminateDrawable(fadingCircle);
        progressBar.setVisibility(View.VISIBLE);

        RecyclerView mRecylerView = findViewById(R.id.recycler_view_user_control);
        mRecylerView.setHasFixedSize(true);
        RecyclerView.LayoutManager layoutManager=new LinearLayoutManager(User_Status.this);
        user_status_adapter =new user_status_adapter(User_Status.this,mDataList);
        mRecylerView.setLayoutManager(layoutManager);
        mRecylerView.setAdapter(user_status_adapter);

        getUserInformation();

        searchText.getEditText().addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {

                user_status_adapter.getFilter().filter(s);

            }
        });


    }

    private void getUserInformation() {
        DatabaseReference mRef= FirebaseDatabase.getInstance().getReference("Users");
        mRef.orderByChild("username").addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
                for (DataSnapshot snapshot1:snapshot.getChildren())
                {
                    if (snapshot1.exists())
                    {
                        UserHelperClass userHelperClass=snapshot1.getValue(UserHelperClass.class);
                        assert userHelperClass !=null;
                        if(!userHelperClass.getUsername().equals("1"))
                        {
                            mDataList.add(userHelperClass);
                        }

                    }else
                    {
                        Log.d("Error","No Snapshot exists");}
                }

                progressBar.setVisibility(View.GONE);
            }

            @Override
            public void onCancelled(@NonNull DatabaseError error) {
                Log.d("Database Error","Failed to fatch data from the server");
            }
        });
    }
}

这是我的适配器类

public class user_status_adapter extends RecyclerView.Adapter<user_status_adapter.MyViewHolder> implements Filterable {

    private final Context mContext;
    private final List<UserHelperClass> mFilteredList;
    private final List<UserHelperClass> mDataList;

    public user_status_adapter(Context mContext,List<UserHelperClass>mFilteredList)
    {
        this.mContext = mContext;
        this.mFilteredList = mFilteredList;
        mDataList = new ArrayList<>(mFilteredList);
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.user_status_single_row, parent, false);
        return new MyViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        final UserHelperClass userHelperClass = mFilteredList.get(position);

        holder.fullname.setText(userHelperClass.getFullname());
        holder.aadhar.setText(userHelperClass.getUsername());
        holder.contactno.setText(userHelperClass.getContactno());

        if (userHelperClass.getStatus().equals("Active")) {
            holder.activate.setVisibility(View.GONE);
            holder.deactivate.setVisibility(View.VISIBLE);
        } else {
            holder.deactivate.setVisibility(View.GONE);
            holder.activate.setVisibility(View.VISIBLE);
        }


        String uid = userHelperClass.getUid();
        String username = userHelperClass.getUsername();
        String fullname = userHelperClass.getFullname();

        holder.deactivate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setWarningDialog("Deactivate", username, uid);
            }
        });

        holder.activate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setWarningDialog("Activate", username, uid);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mFilteredList.size();
    }

    @Override
    public Filter getFilter() {
        return filteredList;
    }

    //filter function
    private final Filter filteredList = new Filter() {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            List<UserHelperClass> filterlist = new ArrayList<>();
            if (constraint == null || constraint.length() == 0) {
                filterlist.addAll(mDataList);
            } else {
                String pattern = constraint.toString().toLowerCase().trim();
                for (UserHelperClass item : mDataList) {
                    if ((item.getFullname().toLowerCase().contains(pattern) && (item.getStatus().equals("Active"))) || (item.getFullname().toLowerCase().contains(pattern) && (item.getStatus().equals("Deactive")))) {
                        filterlist.add(item);
                    }
                }
            }
            FilterResults filterResults = new FilterResults();
            filterResults.values = filterlist;
            return filterResults;
        }

        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            mFilteredList.clear();
            mFilteredList.addAll((List) results.values);
            notifyDataSetChanged();
        }
    };

    //view holder class
    public static class MyViewHolder extends RecyclerView.ViewHolder{
        TextView fullname, aadhar, contactno;
        Button activate, deactivate;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            fullname = itemView.findViewById(R.id.user_status_single_name);
            aadhar = itemView.findViewById(R.id.user_status_single_aadhar);
            contactno = itemView.findViewById(R.id.user_status_single_contact);

            activate = itemView.findViewById(R.id.user_status_active_button);
            deactivate = itemView.findViewById(R.id.user_status_deactive_button);

        }
    }

    private void setWarningDialog(String string, String username, String uid) {

        new KAlertDialog(mContext, KAlertDialog.WARNING_TYPE)
                .setTitleText("   !! Warning !!   ")
                .setTitleTextSize(28)
                .setContentText("\n Are you sure want to " + string + " User")
                .setContentTextSize(18)
                .setConfirmText("Yes")
                .showConfirmButton(true)
                .setCancelText("No")
                .showCancelButton(true)
                .confirmButtonColor(R.drawable.button_background_white, mContext)
                .cancelButtonColor(R.drawable.button_background, mContext)
                .setConfirmClickListener(new KAlertDialog.KAlertClickListener() {
                    @Override
                    public void onClick(KAlertDialog kAlertDialog) {
                        if (string.equals("Deactivate")) {
                            setDeactiveUser(username, uid);
                            kAlertDialog.dismissWithAnimation();
                        } else {
                            setActiveUser(username, uid);
                            kAlertDialog.dismissWithAnimation();
                        }
                    }
                })
                .setCancelClickListener(new KAlertDialog.KAlertClickListener() {
                    @Override
                    public void onClick(KAlertDialog sDialog) {
                        sDialog.dismissWithAnimation();

                    }


                })
                .show();


    }

    private void setDeactiveUser(String uname, String UID) {
        DatabaseReference mRef = FirebaseDatabase.getInstance().getReference("Users");
        mRef.child(uname).child("status").setValue("Deactive").addOnSuccessListener(new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
                DatabaseReference mRefuid = FirebaseDatabase.getInstance().getReference("authenticated_User/Users");
                mRefuid.child(UID).child("status").setValue("Deactive").addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        // setSuccessfulDialog("Deactivated");
                        DatabaseReference mRefData_Entry=FirebaseDatabase.getInstance().getReference("User_Data_Entry");
                        mRefData_Entry.child(uname).addValueEventListener(new ValueEventListener() {
                            @Override
                            public void onDataChange(@NonNull DataSnapshot snapshot) {
                                for (DataSnapshot snapshot1:snapshot.getChildren())
                                {   snapshot1.child("status").getRef().setValue("Deactive");

                                    //DatabaseReference mRefset=FirebaseDatabase.getInstance().getReference("User_Data_Entry");
                                    //mRefset.child(uname).child(snapshot.getKey()).child("status").setValue("Deactive");
                                }

                            }

                            @Override
                            public void onCancelled(@NonNull DatabaseError error) {
                              //  setDatabaseErrorDialog();
                            }
                        });

                        setSuccessfulDialog("Deactivated");
                    }
                });

            }
        });
    }

    private void setActiveUser(String uname, String UID) {
        DatabaseReference mRef = FirebaseDatabase.getInstance().getReference("Users");
        mRef.child(uname).child("status").setValue("Active").addOnSuccessListener(new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
                DatabaseReference mRefuid = FirebaseDatabase.getInstance().getReference("authenticated_User/Users");
                mRefuid.child(UID).child("status").setValue("Active").addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        // setSuccessfulDialog("Activated");
                        DatabaseReference mRefData_Entry=FirebaseDatabase.getInstance().getReference("User_Data_Entry");
                        mRefData_Entry.child(uname).addValueEventListener(new ValueEventListener() {
                            @Override
                            public void onDataChange(@NonNull DataSnapshot snapshot) {
                                for (DataSnapshot snapshot1:snapshot.getChildren())
                                {
                                    snapshot1.child("status").getRef().setValue("Active");
                                }

                            }

                            @Override
                            public void onCancelled(@NonNull DatabaseError error) {
                                //setDatabaseErrorDialog();
                            }
                        });

                        setSuccessfulDialog("Activated");
                    }
                });

            }
        });
    }

    private void setSuccessfulDialog(String string) {

        new KAlertDialog(mContext, KAlertDialog.CUSTOM_IMAGE_TYPE)
                .setTitleText("   !! Successful !!   ")
                .setTitleTextSize(28)
                .setContentText("Good Job !!!\nUser has been Successfully " + string)
                .setContentTextSize(18)
                .setConfirmText("OK")
                .setCustomImage(R.drawable.check, mContext)
                .showConfirmButton(true)
                .confirmButtonColor(R.drawable.button_background_white, mContext)
                .setConfirmClickListener(new KAlertDialog.KAlertClickListener() {
                    @Override
                    public void onClick(KAlertDialog kAlertDialog) {
                        kAlertDialog.dismissWithAnimation();
                        Intent intent = new Intent(mContext, User_Status.class);
                        mContext.startActivity(intent);
                        ((User_Status) mContext).finish();
                    }
                })
                .show();


    }
}

日志猫

2021-04-08 21:19:47.513 4696-4803/com.example.aadhar_dhar D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2021-04-08 21:19:51.189 4696-4696/com.example.aadhar_dhar W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@a999727
2021-04-08 21:19:51.194 4696-4696/com.example.aadhar_dhar V/Monotype: SetAppTypeFace- try to flip, app = com.example.aadhar_dhar
2021-04-08 21:19:51.194 4696-4696/com.example.aadhar_dhar V/Monotype:     Typeface getFontPathFlipFont - systemFont = default#default
2021-04-08 21:19:58.307 4696-4696/com.example.aadhar_dhar W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@c72c6ae
2021-04-08 21:19:58.311 4696-4696/com.example.aadhar_dhar V/Monotype: SetAppTypeFace- try to flip, app = com.example.aadhar_dhar
2021-04-08 21:19:58.311 4696-4696/com.example.aadhar_dhar V/Monotype:     Typeface getFontPathFlipFont - systemFont = default#default
2021-04-08 21:20:08.284 4696-4696/com.example.aadhar_dhar W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@81450f9
2021-04-08 21:20:08.288 4696-4696/com.example.aadhar_dhar V/Monotype: SetAppTypeFace- try to flip, app = com.example.aadhar_dhar
2021-04-08 21:20:08.288 4696-4696/com.example.aadhar_dhar V/Monotype:     Typeface getFontPathFlipFont - systemFont = default#default
2021-04-08 21:20:08.448 4696-4712/com.example.aadhar_dhar W/System: A resource failed to call close. 
2021-04-08 21:20:22.358 4696-4696/com.example.aadhar_dhar W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@9bceedc
2021-04-08 21:20:22.363 4696-4696/com.example.aadhar_dhar V/Monotype: SetAppTypeFace- try to flip, app = com.example.aadhar_dhar
2021-04-08 21:20:22.363 4696-4696/com.example.aadhar_dhar V/Monotype:     Typeface getFontPathFlipFont - systemFont = default#default
2021-04-08 21:20:24.288 4696-4710/com.example.aadhar_dhar I/ple.aadhar_dha: Background concurrent copying GC freed 1597078(32MB) AllocSpace objects, 0(0B) LOS objects, 39% free, 37MB/61MB, paused 27us total 134.621ms
2021-04-08 21:20:25.763 4696-4710/com.example.aadhar_dhar I/ple.aadhar_dha: Background concurrent copying GC freed 2219918(43MB) AllocSpace objects, 0(0B) LOS objects, 36% free, 42MB/66MB, paused 27us total 152.031ms
2021-04-08 21:20:28.603 4696-4710/com.example.aadhar_dhar I/ple.aadhar_dha: Background concurrent copying GC freed 2126451(42MB) AllocSpace objects, 0(0B) LOS objects, 31% free, 52MB/76MB, paused 30us total 185.849ms
2021-04-08 21:20:31.675 4696-4710/com.example.aadhar_dhar I/ple.aadhar_dha: Background concurrent copying GC freed 2338306(46MB) AllocSpace objects, 0(0B) LOS objects, 27% free, 63MB/87MB, paused 29us total 211.099ms
2021-04-08 21:20:34.384 4696-4710/com.example.aadhar_dhar I/ple.aadhar_dha: Background concurrent copying GC freed 2581184(51MB) AllocSpace objects, 0(0B) LOS objects, 25% free, 68MB/92MB, paused 30us total 223.458ms
2021-04-08 21:20:37.016 4696-4710/com.example.aadhar_dhar I/ple.aadhar_dha: Background concurrent copying GC freed 2775023(53MB) AllocSpace objects, 0(0B) LOS objects, 24% free, 74MB/98MB, paused 49us total 236.490ms
2021-04-08 21:20:39.808 4696-4710/com.example.aadhar_dhar I/ple.aadhar_dha: Background concurrent copying GC freed 2932710(56MB) AllocSpace objects, 0(0B) LOS objects, 24% free, 75MB/99MB, paused 72us total 232.474ms

如果您能解决我的问题,请提前非常感谢

4

0 回答 0