There are two activities, MainActivity and WordActivity. I need to do something when closing WordActivity (i.e. when displaying MainActivity) in MainActivity. Is there any method for this?

    1 answer 1

    You need to run WordActivity with

    startActivityForResult

     static final int SOME_REQUEST = 123; //поле Mainactivity ... //в методе где открываете WordActivity Intent intent = new Intent(Mainactivity.this, WordActivity.class); startActivityForResult(intent, SOME_REQUEST); 

    and process the result in

    onActivityResult

     @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SOME_REQUEST) { //здесь Вы вернулись с WordActivity //в зависимости от результата можете обработать действия //из Intent data можете доставать данные, если Вы туда их сложили в WordActivity } } 

    Detailed documentation with examples.

    • And these actions will allow to do something in MainActivity after WordActivity closes? - Kolkhoznik
    • @ Collective farmer updated the answer with a few comments. - VAndrJ
    • Yes, I understand .. Thank you. And if I need to update the icon at the button which is in the custom ListView. How can I get a button from this ListView from this method? - Kolkhoznik