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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:24:24+00:00 2026-06-16T15:24:24+00:00

I have defined some SharedPreferences in my Main Activity (called ScoreboardActivity). The values are

  • 0

I have defined some SharedPreferences in my Main Activity (called ScoreboardActivity). The values are definitely either getting retrieved or the correct default value is working. However, I have now tried to setup a SettingsActivity screen so that the user can change these values and it isn’t working correctly. When the new Activity is opening, the values aren’t loading into the fields in the XML layout.

(as you will be able to tell, I’m very new to this so please be kind)

Here is my ScoreboardActivity code related to the Shared Preferences (this works):

// get the preferences
        prefs = getPreferences(MODE_PRIVATE);

        // Load the values or defaults from the SharedPreferences
        msMainClockStart = prefs.getLong( "Default_Main_Clock", 480000);    // 8 minute default
        useShotClock = prefs.getBoolean( "Use_ShotClock", false );
        msShotClockStart = prefs.getLong( "Default_Shot_Clock", 24000);     // 24 second default
        tvPeriodPrefix = prefs.getString( "Period_Prefix", getResources().getString(R.string.period) );
        valMaxPeriods = prefs.getInt( "Max_Periods", 4);


Here is my code when the menu button is pressed and Settings is clicked on (I think this is wrong but the settings.xml page does open:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        setContentView(R.layout.settings);

        return super.onOptionsItemSelected(item);
    }

Here is my SettingsActivity:

 package com.example.ultimatescoreclock;

    import android.app.Activity;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.widget.CheckBox;
    import android.widget.EditText;

    public class SettingsActivity extends Activity {

    ScoreboardActivity scoreboard = new ScoreboardActivity();
    SharedPreferences settings = scoreboard.prefs;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        EditText
            strMainMinutes,
            strShotSeconds,
            strPeriodPrefix,
            strMaxPeriods;

        CheckBox
            cbUseShotClock;

        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);

        // Load the values or defaults from the SharedPreferences
        scoreboard.msMainClockStart = settings.getLong( "Default_Main_Clock", 480000);  // 8 minute default
        scoreboard.useShotClock = settings.getBoolean( "Use_ShotClock", true );
        scoreboard.msShotClockStart = settings.getLong( "Default_Shot_Clock", 24000);       // 24 second default
        scoreboard.tvPeriodPrefix = settings.getString( "Period_Prefix", getResources().getString(R.string.period) );
        scoreboard.valMaxPeriods = settings.getInt( "Max_Periods", 4);

        strMainMinutes = (EditText) findViewById(R.id.numMainMinutes);
        cbUseShotClock = (CheckBox) findViewById(R.id.cbUseShotClock);
        strShotSeconds = (EditText) findViewById(R.id.numShotSeconds);
        strPeriodPrefix = (EditText) findViewById(R.id.periodPrefix);
        strMaxPeriods = (EditText) findViewById(R.id.periodMax);


        strMainMinutes.setText( Long.toString(scoreboard.msMainClockStart / 1000) );
        cbUseShotClock.setChecked( scoreboard.useShotClock );
        strShotSeconds.setText( Long.toString(scoreboard.msShotClockStart / 1000) );
        strPeriodPrefix.setText( scoreboard.tvPeriodPrefix );
        strMaxPeriods.setText( Integer.toString(scoreboard.valMaxPeriods) );
    }


}

Here is my XML Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/lblMainClock"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Main Clock Default (mins)" />

<EditText
    android:id="@+id/numMainMinutes"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:ems="10"
    android:inputType="number"
    android:minEms="4" />

<CheckBox
    android:id="@+id/cbUseShotClock"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|start"
    android:text="Use Shot Clock" />

<TextView
    android:id="@+id/lblShotClock"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Shot Clock Default (secs)" />

<EditText
    android:id="@+id/numShotSeconds"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:ems="10"
    android:inputType="number"
    android:minEms="4" >

    <requestFocus />
</EditText>

<TextView
    android:id="@+id/lblPeriodPrefix"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Period Prefix (e.g. Q, Shift, etc)" />

<EditText
    android:id="@+id/periodPrefix"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10" />

<TextView
    android:id="@+id/lblMaxPeriods"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Maximum Number of Periods" />

<EditText
    android:id="@+id/periodMax"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minEms="4" />

  • 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-06-16T15:24:26+00:00Added an answer on June 16, 2026 at 3:24 pm

    You should really learn basics of android first.

    The way you are instantiating ScoreboardActivity is not the android’s way of instantiation of Activity.

    In your code, I didn’t find any code related to SAVING DATA to SharedPreferences. the code you put there is only for retrieving data from SharedPreferences in both classes.

    and when you change values using UI components, like changing the CheckBox state, changing the text in EditText etc, you need to save them again to SharedPreferences while you are finalizing the value (asking user to save or finishing current Activity).

    I would suggest you to read some basics of android-sdk.

    • Here are some example and explanation on saving and retrieving
      data from SharedPreferences
    • Here is an android tutorial about how to start Activity.
      (switching between Activities)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some activities in my application. In main activity I have defined the
I have defined some Error Messages and my Question is, how to access them
In express, I have defined some routes app.post(/api/v1/client, Client.create); app.get(/api/v1/client, Client.get); ... I have
I have a problem with Focusable Buttons on Eclipse Rap. I have defined some
I have defined a table type PL/SQL variable and added some data there. create
I have made a Java class where I have defined a constructor and some
I would like to export some macros that I have defined and be able
I have some CCS defined as following: .FW_Buttons { -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius:
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
I have a ListBox defined in my app that I've populated with some static

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.