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 6033163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:26:37+00:00 2026-05-23T05:26:37+00:00

My app is a basic golf counter that is mainly an array of hole

  • 0

My app is a basic golf counter that is mainly an array of “hole” objects that contains 2 integers; hole number and the stroke number.

I am trying to save the information to the phone as a string when the app is killed and then read it back in and use String.split() and Integer.parse() to write the information back into the array.

I use OnPause() and OnResume() and I have been testing my app by pressing the back arrow button to see if it is saving. But I cant seem to get it to work.

Am I right to use OnPause() and OnResume()?

  • 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-23T05:26:38+00:00Added an answer on May 23, 2026 at 5:26 am

    if you wan the values to be saved permanently, then you need to use SharedPreferences like this:

    (within onCreate)
    ...
    SharedPreferences user_info = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    hole = user_info.getInt("hole", 0);
    stroke = user_info.getInt("stroke", 0);
    ...
    }
    
    @Override
    public void onPause()
        {
        super.onPause();
        SharedPreferences user_info = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        user_info.edit()
        user_info.putInt("hole", hole)
        user_info.putInt("strike", stroke)
        user_info.commit();
        }
    

    if you don’t include the commit() then nothing happens. also you can (and i would) use method chaining for the SharedPreferences, i just thought i should keep it simple.

    it is just as easy to leave them as int (or int[] i wasnt entirely clear which you were going for) instead of dealing with all that splitting and parseing. now if you are trying to add them so that everytime you quit, your hole and strike are added to an evergrowing array, thats a little more complex and i can help you with that too if thats the case.

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

Sidebar

Related Questions

Hey--I'm writing a basic Rails app that uses the digg API. I'm trying to
I'm trying to debug my iPhone app (a basic counter) and I have a
I've been trying to get a basic app working that doesnt use an XIB.
I am trying to write a basic app that will read data off a
I'm trying to create an app in Visual Basic that will allow a user
I am building a basic POS app for my cousin's pharmacy store so that
I have a very basic doubt regarding the method that gets executed when app
My Basic Goal A Rails app that can load new content via Ajax while
I have a basic app that allows user1 to create a redeemable code. user1
I am trying to develop a basic app to display information in 2 tabs,

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.