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
481 views
in Technique[技术] by (71.8m points)

android - onSavedInstanceState vs. SharedPreferences

I have 7 activites all with back and forth navigation buttons between the rest; activites consist of editTexts, Spinners, textViews, TimePickers, DatePickers, and checkboxes.

I want all UI to be present and saved through navigation of an application instance; however on application termination everything needs to default.

My 8th activity collects all UI and places into an email . . .fyi

I have read alot about both onSavedInstanceState & SharedPreferences way of saving the data as activities go back and forth . . .

Which would be better for me?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

It will depend on how you want to manage the data. Both options (and more) are feasible:

  • If you want to fill once and keep the data even if the app gets killed, use SharedPreferences.
  • If it's volatile data that will have to be reentered differently some other time (i.e., days later), then use onSavedInstanceState.
  • If you want to keep multiple datasets on the same device, then use a SQLiteDatabase

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

...