excuse me, i want to create an auto increment for order_id as a firebase key at my apps that i work on it. But every time i add new order, the previous order_id was replace by a new one. I had try many ways, but the result is nothing, the previous order_id, always replace by a new one.

Here i attach my firebase tree database

enter image description here

And here is my code to add the order to firebase

confirmOrder.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ref.addListenerForSingleValueEvent(new ValueEventListener() {
                    public void onDataChange(@NonNull DataSnapshot snapshot) {
                        for(DataSnapshot dsCart : snapshot.getChildren()){
                            Cart c = dsCart.getValue(Cart.class);
                                menuName = c.getMenuName();
                                menuQuantity = c.getQuantity();
                                menuPrice = c.getMenuPrice();
                                menuType = c.getMenuType();
                            else {
                                Toast.makeText(CartList.this, "No data at Cart", Toast.LENGTH_SHORT).show();
                            if(table != null){
                                subtotal = Integer.parseInt(txtTotalPrice.getText().toString());
                                pay = Integer.parseInt(edtPayment.getText().toString());
                                change = pay - subtotal;
                                Log.d("total", String.valueOf(subtotal));
                                Order ord = new Order(String.valueOf(order_id),table, date, subtotal, pay, change, status);
                                OrderDetails details = new OrderDetails(String.valueOf(order_id), c.getMenuName(), c.getQuantity(), Integer.parseInt(c.getMenuPrice()));


I very thank full for any sugesttion and feedback.

Anonymous Asked question May 14, 2021