Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

android - Where to Initialize Shared Preferences for better performance

I am following Single Activity-Multiple Fragments design pattern where navigation between fragments is done via Navigation Graph.

I need Shared Preference for the app.
However, where should I initialize it ?
Inside Activity or inside Fragment ?

In case, If I need to initialize inside fragments, then shall I do the initialization in onCreate() callback of Fragment.

I studied all the Activity and Fragment Lifecycle before posting this question.
But I feel like initialize Shared Preference in Fragment then every time the fragment is destroyed/re-created the initialization will happen.
Hence need guidance to build a performant and robust solution.

Please advice.

question from:https://stackoverflow.com/questions/65934440/where-to-initialize-shared-preferences-for-better-performance

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...