android - Saving fragment state on navigating up -


situation:

starting host activitya/fragment a, click on button start host activityb/fragment b. fragment b fragment enables filtering options fragment a. after selecting options, user can press navigate button return fragment a.

problem:

i state of options selected retained when navigating fragment b more once. since filtering option, preferable not save in storage beyond duration of application (it's filtering. not necessary keep information stored long time. in between navigation).

things i've tried:

  • onsavedinstancestate - realized onnavigateupto() / finish() don't trigger onsavedinstancestate
  • android:launchmode="singletop" - because activity finished , destroyed backstack, no instance of activity available receive new intent.
  • setretaininstance - activity destroyed attached fragment destroyed.

a possible solution i've found use setresult , return values fragment a. put these values extras new intent when starting fragment b again. solution seems clunky. there cleaner solution allows fragment b "remember" state instead of passing values , forth?

as have stated fragment destroyed when user goes there no way "state" back. not make sense store state logically fragment/activity not needed platform point of view.

so way 'remember' state of fragment store filter data in other variable(s) , give when re-launched. trying fine i.e. return filter data result , send fragment @ re-launch.

to make simpler may write class containing filter options , make parcelable. may choose make global may not need send across activities, not prefer though.

one ux issue when user presses up/back expected user has cancelled operation. user expect when press cancels operation , when press "apply" applies filters. may need rethink user experience applying filter on press.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -