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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:18:26+00:00 2026-05-26T18:18:26+00:00

I have 2 activities. In activity A when pressing a button sends you to

  • 0

I have 2 activities. In activity A when pressing a button sends you to activity B, in B it asks for input and returns that input to A where it is saved via SharedPreferences.When i try to save that value using SharedPreferences my app crashes. I cant figure out whats wrong. Here is activity A code which should save and display the value passed from activity B.

p.s.
using intents to pass the value back to A from B there is no problem, its just saving that value that is causing the issue.

TextView teamScore1;
SharedPreferences Score01;
public static String strTScore01 = "MySHaredString";

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.game);

           Score01 = getSharedPreferences(strTScore01, 0);
    String dataReturned01 = Score01.getString("sharedString",
            "Cant LOAD data");
    teamScore1.setText(dataReturned01);
            initialize();
    intents();

}
private void initialize()....
private void intents() {
    if (getIntent().hasExtra("teamScore1")) {

        Intent i = getIntent();
        stringData1 = i.getStringExtra("teamScore1");


        // SCORE VALUES
        if (stringData1.length()> 0) {
            //calculations and data manipulation 
            intTScore_1 = Integer.parseInt(stringData1);
            total = intTScore_1 + total; // add to current total
            stringData1 = Integer.toString(total);


            SharedPreferences.Editor editor = Score01.edit();
            editor.putString("sharedString", stringData1);
            editor.commit();
            Score01 = getSharedPreferences(strTScore01, 0);
            String dataReturned1 = Score01.getString("sharedString",
                    "Cant LOAD data");
            teamScore1.setText(dataReturned1);

logcat…..

11-07 19:36:01.712: D/AndroidRuntime(905): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<

11-07 19:36:01.712: D/AndroidRuntime(905): CheckJNI is ON

11-07 19:36:01.832: D/AndroidRuntime(905): --- registering native functions ---

11-07 19:36:02.342: D/AndroidRuntime(905): Shutting down VM

11-07 19:36:02.342: D/dalvikvm(905): Debugger has detached; object registry had 1 entries

11-07 19:36:02.372: I/dalvikvm(905): JNI: AttachCurrentThread (from ???.???)

11-07 19:36:02.372: I/AndroidRuntime(905): NOTE: attach of thread 'Binder Thread #3' failed

11-07 19:36:02.732: D/AndroidRuntime(913): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<

11-07 19:36:02.732: D/AndroidRuntime(913): CheckJNI is ON

11-07 19:36:02.852: D/AndroidRuntime(913): --- registering native functions ---

11-07 19:36:03.343: I/ActivityManager(59): Force stopping package com.petermihaylov.android.cardcounter uid=10039

11-07 19:36:03.343: I/Process(59): Sending signal. PID: 898 SIG: 9

11-07 19:36:03.363: I/UsageStats(59): Unexpected resume of com.thenewboston.travis while already resumed in com.petermihaylov.android.cardcounter

11-07 19:36:03.363: I/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.petermihaylov.android.cardcounter/.MainActivity }

11-07 19:36:03.373: I/WindowManager(59): WIN DEATH: Window{45067ea0 com.petermihaylov.android.cardcounter/com.petermihaylov.android.cardcounter.NewGame paused=false}

11-07 19:36:03.447: D/AndroidRuntime(913): Shutting down VM

11-07 19:36:03.454: D/jdwp(913): Got wake-up signal, bailing out of select

11-07 19:36:03.454: D/dalvikvm(913): Debugger has detached; object registry had 1 entries

11-07 19:36:03.505: I/AndroidRuntime(913): NOTE: attach of thread 'Binder Thread #3' failed

11-07 19:36:03.603: I/ActivityManager(59): Start proc com.petermihaylov.android.cardcounter for activity 
com.petermihaylov.android.cardcounter/.MainActivity: pid=920 uid=10039 gids={}

11-07 19:36:03.663: W/InputManagerService(59): Got RemoteException sending setActive(false) notification to pid 898 uid 10039

11-07 19:36:03.873: W/ActivityThread(920): Application com.petermihaylov.android.cardcounter is waiting for the debugger on port 8100...

11-07 19:36:03.913: I/System.out(920): Sending WAIT chunk

11-07 19:36:03.923: I/dalvikvm(920): Debugger is active

11-07 19:36:03.953: I/System.out(920): Debugger has connected

11-07 19:36:03.953: I/System.out(920): waiting for debugger to settle...

11-07 19:36:04.193: I/System.out(920): waiting for debugger to settle...

11-07 19:36:04.393: I/System.out(920): waiting for debugger to settle...

11-07 19:36:04.646: I/System.out(920): waiting for debugger to settle...

11-07 19:36:04.843: I/System.out(920): waiting for debugger to settle...

11-07 19:36:05.057: I/System.out(920): waiting for debugger to settle...

11-07 19:36:05.253: I/System.out(920): waiting for debugger to settle...

11-07 19:36:05.513: I/System.out(920): waiting for debugger to settle...

11-07 19:36:05.746: I/System.out(920): waiting for debugger to settle...

11-07 19:36:05.950: I/System.out(920): waiting for debugger to settle...

11-07 19:36:06.154: I/System.out(920): waiting for debugger to settle...

11-07 19:36:06.358: I/System.out(920): debugger has settled (1438)

11-07 19:36:07.377: I/ActivityManager(59): Displayed activity com.petermihaylov.android.cardcounter/.MainActivity: 3784 ms 
(total 33895 ms)

11-07 19:36:09.143: I/ActivityManager(59): Starting activity: Intent { act=com.petermihaylov.android.NEWGAME cmp=com.petermihaylov.android.cardcounter/.NewGame (has extras) }

11-07 19:36:10.014: I/ActivityManager(59): Displayed activity com.petermihaylov.android.cardcounter/.NewGame: 761 ms (total 761 ms)

11-07 19:36:14.062: I/ActivityManager(59): Starting activity: Intent { act=com.petermihaylov.android.GAME cmp=com.petermihaylov.android.cardcounter/.Game (has extras) }

11-07 19:36:24.117: W/ActivityManager(59): Launch timeout has expired, giving up wake lock!

11-07 19:36:24.186: W/ActivityManager(59): Activity idle timeout for HistoryRecord{45062c78 com.petermihaylov.android.cardcounter/.Game}

11-07 19:36:29.451: W/ActivityManager(59): Activity destroy timeout for HistoryRecord{4505ae90 com.petermihaylov.android.cardcounter/.NewGame}

After several long hours of try and catch statements narrowing down the problem I think i have solved it. Here is the code I hope it helps someone

protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game);
        initialize();
        intents();

        Score01 = getSharedPreferences(strTScore1, 0);
        String dataReturned1 = Score01.getString("sharedString",
                "Cant LOAD data");
        teamScore1.setText(dataReturned1);
    }

    private void initialize() {...

    private void intents() {
        if (getIntent().hasExtra("teamScore1")) {
            Intent i = getIntent();
            stringData1 = i.getStringExtra("teamScore1");
            Score01 = getSharedPreferences(strTScore1, 0);

            if (stringData1.length() > 0) {


                intTScore_1 = Integer.parseInt(stringData1);
                total = intTScore_1 + total; // add to current total
                stringData1 = Integer.toString(total);

                SharedPreferences.Editor editor = Score01.edit();
                editor.putString("sharedString", stringData1);
                editor.commit();

            }
  • 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-26T18:18:27+00:00Added an answer on May 26, 2026 at 6:18 pm
    protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.game);
            initialize();
            intents();
    
            Score01 = getSharedPreferences(strTScore1, 0);
            String dataReturned1 = Score01.getString("sharedString",
                    "Cant LOAD data");
            teamScore1.setText(dataReturned1);
        }
    
        private void initialize() {...
    
        private void intents() {
            if (getIntent().hasExtra("teamScore1")) {
                Intent i = getIntent();
                stringData1 = i.getStringExtra("teamScore1");
                Score01 = getSharedPreferences(strTScore1, 0);
    
                if (stringData1.length() > 0) {
    
    
                    intTScore_1 = Integer.parseInt(stringData1);
                    total = intTScore_1 + total; // add to current total
                    stringData1 = Integer.toString(total);
    
                    SharedPreferences.Editor editor = Score01.edit();
                    editor.putString("sharedString", stringData1);
                    editor.commit();
    
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 Activities...the first Activity have a button that start third Activity. The
I have 2 activities. In child activity i have put something like that in
I have 3 activities. 1st activity has a 'go right' image button. (to move
In my application I have several activities, the main screen has 4 buttons that
I have a bunch of Workflow foundation 4.0 RC code activities that consume web
I want to have an options menu that is available to all Activities in
Hi i'm facing this problem. I have an application with 2 activities: -Activity A
I have two activities. Home activity contain a list view with two buttons named
I have 2 activities. MyMain MySecond I call MySecond activity in MyMain activity. And
I have three activities A->B->C.when i am in B activity i click the home

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.