Search code examples
androidandroid-fragmentsandroid-fragmentactivity

How to show data without calling an api on back press?


Suppose ActivityA calls an API to load the data, after that clicking on one content, I move to ActivityB. Now When I press BackPress the ActivtyB, I do not want to call API again and load the data. I want it should show the old data without calling an API again.

How can I achieve this? Should I call finish() on onBackPress() or there is some another way to achieve this ?


Solution

  • When the Activity B finishes , Activity A will again get the focus of UI . Activity's A onResume method will be called . Make sure not to write the fetch API logic in onResume and onPause methods and you will have old data from Activity A. Alternatively you can use

    Loaders and Syncers