K
K
kirawa2018-03-23 08:45:24
Android
kirawa, 2018-03-23 08:45:24

Why does the Firebase Database encountered an OutOfMemoryError application crash?

Good afternoon. An error occurs - java.lang.RuntimeException: Firebase Database encountered an OutOfMemoryError. You may need to reduce the amount of data you are syncing to the client (eg by using queries or syncing a deeper path).

public class FragmentFireBaseMessageTreeView extends Fragment implements ChildEventListener{
 @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

        iChildClickFireBaseFragment = (IChildClickFireBaseFragment)getFragmentManager().findFragmentById(R.id.contentMain);
        View rootView = inflater.inflate(R.layout.fragment_firebase_message,container,false);
        expandableListView = rootView.findViewById(R.id.exListView);

        notificationsGroup = new LinkedHashMap<>();
        notificationsGroup.put(WEB, notificationsListWeb);
        notificationsGroup.put(ODIN_C, notificationsList1c);
        notificationsGroup.put(MEscort, notificationsListMEscort);
        adapter = new FireBaseMessageExpAdapter(getActivity(),notificationsGroup);
        expandableListView.setAdapter(adapter);

        databaseRef = FirebaseDatabase.getInstance().getReference().child("notifications");
        region = App.getRegion(getActivity());
        token = FirebaseInstanceId.getInstance().getToken();
        code = App.get(getActivity()).getCodeAgent();
        Query queryToAll = databaseRef.orderByChild("to").equalTo("/topics/all").limitToFirst(10);
        Query queryToCity = databaseRef.orderByChild("to").equalTo("/topics/"+region).limitToFirst(10);
        Query queryToCodeAndRegion = databaseRef.orderByChild("code").equalTo(region+"_"+code).limitToFirst(10);
queryToCodeAndRegion.addChildEventListener(this);
        queryToAll.addChildEventListener(this);
        queryToCity.addChildEventListener(this);
        expandableListView.setOnChildClickListener(this);
        dialog = new ProgressDialog(getActivity());
        dialog.setMessage("Please wait...");
        dialog.show();
        return rootView;
}

@Override
    public void onChildAdded(DataSnapshot dataSnapshot, String s) {
        if (dataSnapshot.hasChildren()){
            FireBaseNotification notification = dataSnapshot.getValue(FireBaseNotification.class);
addNotificationForAdapter(notification,dataSnapshot);
}
dialog.dismiss();
}

private void addNotificationForAdapter(FireBaseNotification notification,DataSnapshot dataSnapshot){
        if (notification != null) {
            notification.setId(dataSnapshot.getKey());
            switch (notification.getTag()){
                case WEB:
                    notificationsListWeb.add(notification);
                    notificationsGroup.put(WEB, notificationsListWeb);
                    break;
                case ODIN_C:
                    notificationsList1c.add(notification);
                    notificationsGroup.put(ODIN_C, notificationsList1c);
                    break;
                case MEscort:
                    notificationsListMEscort.add(notification);
                    notificationsGroup.put(MEscort, notificationsListMEscort);
                    break;
            }
            adapter.notifyDataSetChanged();
        }
    }

Actually, I’ll add to all this that for this month the download quota has been exceeded and it is proposed to switch to a paid tariff. Could it be because of this??

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question