Ofir Bar
02/24/2020, 9:08 AMUserFragment, the fragment display data of a User, the data is fetched from the SharedPreferences.
EditUserActivity :Edits the data of the user, and once editing is done, this activity calls finish() and we go back to MainActivity, which displays UserFragment
When returning to UserFragment, the data displayed is the old data for the user (the unedited data)
I can think of 2 ways to make the fragment display fresh data, can anyone think of a smarter way, or explain which way below is better in terms of design?
1. Make UserFragment start EditUserActivity with startActivityForResult , and return a success or failure code, if success we do some data refresh.
2. Make UserFragment terminate itself once we navigate to EditUserActivity, and make EditUserActivity launch MainActivity with UserFragment on a backpress or successful save.
Even if there is a way that is tricky and should not be in production i would like to know as I want to expand my skills please, thank you! 🙂Francisco Javier Ruiz Rodriguez
02/24/2020, 9:37 AMonResume of UserFragment, get info of user in SharedPreferences is the best optionOfir Bar
02/24/2020, 9:53 AMonStart as there might be a phone call/etc and then there will be additional call to render the UIHitender Pannu
02/24/2020, 11:03 AMOfir Bar
02/24/2020, 1:16 PMonViewCreated, it didn’t worked, as if I return from EditUserActivity to MainActivity, UserFragment won’t call onViewCreatedHitender Pannu
02/25/2020, 5:46 AMbhatnagarm
02/25/2020, 2:24 PMbhatnagarm
02/25/2020, 2:25 PMOfir Bar
02/26/2020, 11:45 AMonStop()
Only after that we have onDestroyView() and onDestroy()Cấn Văn Nghị
03/02/2020, 2:03 AMEditUserActivity with startActivityForResult is a good way.