Search code examples
androidrefreshandroid-lifecycleback-stack

Best practise for update view after backstack from new activity


I actually had an activity's fragment which contain a custom tablelayout with checkbox and goned image. Also, when the user click on a button for send mail at selected rows, I would like to update the visibility of the goned images. I called a new activity which is my mail client, so when I press back, the fragment is still there but onCreateView isn't call properly, and my view isn't refresh. So I would like to know which is the best solution to update it (without recreate my fragment programmaticaly).

Thanks in advance :)


Solution

  • If you are starting another Activity for your mail client, instead of just startActivity(intent) use the startActivityForResult(intent, requestCode) method and override onActivityResult (requestCode, resultCode, data).

    Define a constant for your requestCode and use that for startActivityForResult when you start the mail client. When the user returns from the mail client, onActivityResult will be called and the value of its requestCode parameter will be your constant. This is the callback you need to use to set the appropriate visibility for your Views.