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

  • Home
  • SEARCH
  • 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 7944915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:41:42+00:00 2026-06-04T00:41:42+00:00

i have created a MainActivity and a SecondActivity . When onClick MainActivity it starts

  • 0

i have created a MainActivity and a SecondActivity. When onClick MainActivity it starts the SecondActivity. When SecondActivity finish, it returns a value that turns an ImageView.setVisibility(View.VISIBLE); and makes a counter++.

My problem is that when i close the application and then restart it again all the values were cleared and my ImageView turns ImageView.setVisibility(View.INVISIBLE); and the counter == 0 again.

How can i save data (the result of SecondActivity) even if i close the aplication or reboot my mobile? I want to set public void onCreate(Bundle savedInstanceState) { as before i close the application each time i restart it.


What I want is to save “int contadorliga”, “correcto1.setVisibility(View.VISIBLE);” and “correcto2.setVisibility(View.VISIBLE);” so each time I restar the app it is as the latest time it was. This is my code:

package com.fakur.android.futbolquiz;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class Liga extends Activity {
/** Called when the activity is first created. */

static final int LIGA = 0;
int contadorbarcelona = 0;
int contadormadrid = 0;
int contadorliga = 0;

ImageView about;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.liga);
TextView contador1 = (TextView) findViewById(R.id.contador1);
contador1.setText(contadorliga + "/20");
}

public void onBarcelonaClick(View botton) {

Intent intent = new Intent();
intent.setClass(this,Pregunta.class);
intent.putExtra("Barcelona", "Barcelona");
startActivityForResult(intent,LIGA);
}

public void onMadridClick(View botton) {

Intent intent = new Intent();
intent.setComponent(new ComponentName(this,Pregunta.class));
intent.putExtra("Madrid", "Madrid");
startActivityForResult(intent,LIGA);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

TextView contador1 = (TextView) findViewById(R.id.contador1);
ImageView correcto1 = (ImageView) findViewById(R.id.correcto1);
ImageView correcto2 = (ImageView) findViewById(R.id.correcto2);

if (requestCode == LIGA){

  if (resultCode == 1) {

      if(contadorbarcelona == 0){

          correcto1.setVisibility(View.VISIBLE);
          contadorliga++ ;
          contadorbarcelona++;
      }
  }

  if (resultCode == 2) {
      if(contadormadrid == 0){

           correcto2.setVisibility(View.VISIBLE);
           contadorliga++ ;
           contadormadrid++;
      }
  }

}

contador1.setText(contadorliga + "/20");

}
  • 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-04T00:41:44+00:00Added an answer on June 4, 2026 at 12:41 am

    Usage of shared preferences is best fit for you, see here

    Edit:

    • Added source below in response to your comment;

      private static final String PREFERENCES_CONTADORLIGA =  "ChangeThisTextWithSomethingYouPrefer";
      private static final String PREFERENCES_CONTADORLIGA_KEY = "ChangeThisTextWithSomethingYouPrefer";
      
      
      public void onCreate(Bundle savedInstanceState)
      {
      
          // Restore preferences
          SharedPreferences settings = getSharedPreferences(PREFERENCES_CONTADORLIGA, Context.MODE_PRIVATE);
          contadorliga = settings.getInt(PREFERENCES_CONTADORLIGA_KEY, 0);
      }
      
      
      
      protected void onDestroy() 
      {
      
          super.onDestroy();
      
          // We need an Editor object to make preference changes.
          // All objects are from android.context.Context
          SharedPreferences settings = getSharedPreferences(PREFERENCES_CONTADORLIGA, Context.MODE_PRIVATE);
          SharedPreferences.Editor editor = settings.edit();
          editor.putInt(PREFERENCES_CONTADORLIGA_KEY, contadorliga);
      
          // Commit the edits!
          editor.commit();
      }
      

    I hope this should work for you. Good Luck!

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

Sidebar

Related Questions

I have created a mini installer in NSIS that installs patches for my application.
I have created a class of type BaseAdapter that is populated with buttons -
I have TabActivityGroup: MainActivity class contain some tab, that name loading from db. Sales,
So, I have a code: ((Button) findViewById(R.id.run)).setOnClickListener(new View.OnClickListener() { public void onClick(View v) {
I have created an Activity that shows a listview and on swipe action another
I am making an Android app, and have created a custom view to do
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
I have created the following C library for reading an image: typedef struct {
I have created a skin for DotNetNuke 5.x and I attempted to do as
I have created a basic site using ASP.NET routing according to Mike Ormond's 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.