setOnClickListener on activity android

0

I have a button to which I gave a setOnClickListener in the onCreate estor receiving an intent that has an arrayList and the array list is updated when I add more images. I want to finish the life cycle of the app but it is not staying. When I add more images I select the btnPicture button then it sends me to another activity where in this activity I have the cancel in case I no longer want to upload or select but if I cancel it I call Class.superonBackPressed to return to the activity but when come back, the activity is destroyed.

btnHome.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();//./<------------------------CHECAR
            Intent intentMain = new Intent(IndexActivity.this, MainActivity.class);//creo un intent
            startActivity(intentMain);//inicio la actividad

        }//./OnClick
    });//./OnClickLIstener

    btnPicture.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intentPicture = new Intent(IndexActivity.this, PictureActivity.class);//creo un intent
            intentPicture.putExtra("arrayImages", listOfImages);//le paso el arreglo como parametro
            startActivity(intentPicture);//inicio la actividad
            finish();//./<------------------------CHECAR
        }//./OnClick
    });//./OnClickListener
    
asked by Javier fr 24.11.2016 в 00:08
source

1 answer

0

If you call finish() the Activity where you are is destroyed.

So if you call finish() and then do the Intent to open another Activity , if you want to return to the Activity that made the Intent , it will no longer exist as it was destroyed.

finish();
Intent intentMain = new Intent(IndexActivity.this, MainActivity.class);//creo un intent
startActivity(intentMain);//inicio la actividad

If your question is:

  

How I recover my activity as it is and how it was

I recommend you do not call finish() , so that when you call onBackPressed() you can return to your Activity without problem.

    
answered by 24.11.2016 в 00:11