Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6101281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:28:55+00:00 2026-05-23T13:28:55+00:00

In android, I’m trying to create an simple activity allowing me to modify a

  • 0

In android, I’m trying to create an simple activity allowing me to modify a record from a database. In the onCreate method I load the record data from the database in different views on the activity allowing the user to modify the information. If the user click on Ok, I save back the data to the database and call finish(). If the user click on Cancel, I don’t save the data and call finish to return to the previous activity.

Now, I just learnt that it is recommended in the android documentation to commit the unsaved changes to persistent data in the onPause() event.

I see a couple of problems about this. First, onPause() might be called while the data in the field doesn’t form a valid record, so it certainly can’t be saved in the database. Second, even if the data was valid, if I save what should I do if the user later click on the cancel button because he doesn’t want his changes saved. I would no longer have access to the original record. And finaly, if the user click on Cancel and I call finish() to go back to the previous activity onPause() will be called and the data saved while it shouldn’t.

In my opinion it would make more sense to save all the data in the Bundle offered by the onSaveInstanceState() method and reaload it from the onCreate() method if my activity ever gets killed.

How should I handle this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:28:56+00:00Added an answer on May 23, 2026 at 1:28 pm

    This is exactly a case for onSaveInstanceState(). If your app isn’t killed by the system, your data will still be there when the activity is displayed again and the onResume method is called, so no need to save anything in that case. If you app is killed, onSaveInstanceState should do the trick.
    I wouldn’t consider what you describe like unsaved changes, because, as you say so yourself, it could be in an invalid state. It’s just a temporary state.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Android will call onCreate() of my activity whenever it is launched. In the onCreate()
android how to Send a String of data from an android mobile to server
Android 2.1 update 1 Eclipse 3.5 I have a problem reading data from my
Android 2.2 release notes have just been released. ActivityManager.restartPackage method has been deprecated and
Android:How to display images from the web in a ListView?I have the following code
(Android 3.0+) How would I create a Spinner for use as an Action Item
Android 2.1 - Eclipse What steps will reproduce the problem? 1. Create new Texture(managed)
Android activities have a pair of methods onRetainNonConfigurationInstance()/getLastNonConfigurationInstance() for keeping objects expensive for load
android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed error in my application and not sure why.
Android - when getting images from Gallery, they are with wrong orientation. For example,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.