2

I have 3 screens A-landing page, B-listview Page, C-Detail page(Listview)

When i land on A and navigate to B it loads data and artifacts from memory in Async task which adds a bit of delay(this is acceptable since its my 1st load). When i click on specific member in the listview, go to C view and click back button, view B is preserved. However if i click on back to go to view A and try to navigate to listview B it reloads again by calling oncreate. I have tried couple of approaches including android:launchMode="singleTask" , not setting FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_NEW_TASK but could not get the desired result.

How can i prevent B from reloading when navigating from A in subsequent navigation.

Sachin Hegde
  • 151
  • 10
  • You'll need to persist the data in your local database, after the first pull via async task. Then either set a shared preference variable with a boolean saying that data is cached recently or put timestamp in shared preference variable (which you can use to check how long ago was data cached & update accordingly). The main thing is to persist the fetched data, then set some sort of check either by checking for DB exists (or shared preference variable) & then moving to next activity. In case data is found in shared variable or DB, then your async task will load from memory again & send it to B. – MD Naseem Ashraf Mar 18 '19 at 20:57
  • I have sqlite DB from which im fetching data, since i have to re-render heavy items such as images that is adding up to considerable lag. – Sachin Hegde Mar 23 '19 at 03:03
  • Look into RecyclerView, caching and lazy loading images ( http://androidahead.com/2017/01/28/lazy-loading-of-images/ & https://stackoverflow.com/questions/29982341/using-glide-for-android-how-do-i-load-images-from-asset-and-resources/29987915 ) for performance. – MD Naseem Ashraf Mar 23 '19 at 03:11

0 Answers0