Reset the status of an Activity, avoid reopening the information when it reopens

0

The question is, I have a Activity with restaurant list by clicking on a restaurant in the RecyclerView, it takes me to an activity of description and Menu, by clicking on the Activity Shopping Cart, the invoice is shown in a RecyclerView, the problem comes, when I go back and return to the main menu of the restaurant list and enter the cart from a different restaurant, the status of the Shopping Cart Activity continues as before, if not new information command, and if I send new information the RecyclerView is still in the same state.

Try ending the activity every time you leave the Activity but it does not work. Any ideas?

public void AbrirCarrito(View view) {
    Intent PanierIntent = new Intent(this, PanierActivity.class);
    PanierIntent.putExtra("clientes", (Serializable) listaCliente);
    startActivity(PanierIntent);
}

ActivityCarrito

 public class PanierActivity extends AppCompatActivity {
    DateFormat formatoHora = new SimpleDateFormat("hh:mm a");
    Calendar hora = Calendar.getInstance();
    CustomFontButton botonHora;

    private RecyclerView mRecyclerView;
    private RecyclerViewAdapter_Carrito mRecyclerViewAdapterCarrito;
    private LinearLayoutManager layoutManager;
    private List<Cliente> listaCliente = new ArrayList<>();

    CustomFontTextView tvTotalCommande;
    CustomFontTextView tvRemises;
    CustomFontTextView tvTotalRegler;

    double totalCommande;
    double totalDescuento;
    double remises;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_panier);

        remises=getIntent().getIntExtra("descuento",0);

        tvTotalCommande = (CustomFontTextView) findViewById(R.id.tvTotalCommande);
        tvRemises = (CustomFontTextView) findViewById(R.id.tvRemises);
        tvTotalRegler = (CustomFontTextView) findViewById(R.id.tvTotalRegler);

        layoutManager = new LinearLayoutManager(this);
        mRecyclerView = (RecyclerView) findViewById(R.id.rvCarrito);
        mRecyclerView.setLayoutManager(layoutManager);

        listaCliente= (List<Cliente>) getIntent().getSerializableExtra("clientes");
        mRecyclerViewAdapterCarrito = new RecyclerViewAdapter_Carrito(this, listaCliente);
        mRecyclerView.setAdapter(mRecyclerViewAdapterCarrito);

        botonHora = (CustomFontButton) findViewById(R.id.botonHora);
        obtenerHora();

        for(int x=0;x<listaCliente.size();x++){
            totalCommande=totalCommande+listaCliente.get(x).getTotalCliente();
        }
        for(int x=0;x<listaCliente.size();x++){
            totalDescuento=totalDescuento+listaCliente.get(x).getTotalDescuento();
        }

        String prueba= String.valueOf(totalCommande);
        String prueba2=String.valueOf(totalDescuento);

        BigDecimal a = new BigDecimal(prueba);
        BigDecimal b = new BigDecimal(prueba2);

        a=a.setScale(2, RoundingMode.HALF_UP);
        b=b.setScale(2,RoundingMode.HALF_UP);


        tvTotalCommande.setText(String.valueOf(a)+"€");
        tvTotalRegler.setText(String.valueOf(b)+"€");




        tvRemises.setText(String.valueOf((a.subtract(b))+"€"));
    }

    private void obtenerHora(){
        botonHora.setText(formatoHora.format(hora.getTime()));
    }

    public void actualizarHora(View view){
        new TimePickerDialog(this,t,hora.get(Calendar.HOUR_OF_DAY),hora.get(Calendar.MINUTE),true).show();
    }

    TimePickerDialog.OnTimeSetListener t = new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            hora.set(Calendar.HOUR_OF_DAY,hourOfDay);
            hora.set(Calendar.MINUTE,minute);
            obtenerHora();
        }
    };

}
    
asked by Eduardo Ricardez 26.04.2017 в 02:12
source

1 answer

1

In the end, the problem was not in the Activity Cart, but in the Activity that opened this, I had to pass them the complete code, but it is too big to pass it, the list that happened to Cart is static, which I think caused the values of the list to never be lost when changing the Activity, add an onBackPressed with the code to clean the list.

@Override
    public void onBackPressed() {
        super.onBackPressed();
        listaCliente.clear();

    }

Thanks for helping me think.

    
answered by 26.04.2017 / 02:52
source