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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:09:30+00:00 2026-06-13T02:09:30+00:00

I am doing a quiz , in that I have 3 activities Question1 ,

  • 0

I am doing a quiz, in that I have 3 activities Question1, Question2, Question3,and on each there is 4 possible answers (buttons), only one button is correct. I must calculate and display the score of the user at the end of the quiz.

I have done some research and SHAREDPREFERENECES seem to be the solution. But i dont know how to use it can anyone help please. Question1.java code is below: Assume that btnAnswer1a is the correct answer, how do i save the data and then display it in a textview in the last activity.

 Button Answer1, Answer2, Answer3, Answer4;
 public static final String PREFS_NAME = "MyPrefsFile";
 static SharedPreferences settings;
 SharedPreferences.Editor editor;
 int ScoreCount;

 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.answer1);

  settings = getSharedPreferences(PREFS_NAME, 0);
  editor = settings.edit();

  ScoreCount = settings.getInt("ScoreCount", 10);

   Answer1 = (Button) findViewById(R.id.btnAnswer1a);
   Answer2 = (Button) findViewById(R.id.btnAnswer1b);
   Answer3 = (Button) findViewById(R.id.btnAnswer1c);
   Answer4 = (Button) findViewById(R.id.btnAnswer1d);

   Answer1.setOnClickListener(this);
   Answer2.setOnClickListener(this);
   Answer3.setOnClickListener(this);
   Answer4.setOnClickListener(this);

         }

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
switch (arg0.getId()) {


    case R.id.btnAnswer1a:
          Intent Screen1 = new Intent(Answer1.this, Color2.class); 
          Answer1.this.startActivity(Screen1); 
          editor.putInt("ScoreCount", 6);
          editor.commit();
        break;


case R.id.btnAnswer1b:
      Intent Screen = new Intent(Answer1.this, Color2.class); 
    Answer1.this.startActivity(Screen);  
    break;

case R.id.btnAnswer1c:
      Intent Screen3 = new Intent(Answer1.this, Color2.class); 
    Answer1.this.startActivity(Screen3);  
    break;

case R.id.btnAnswer1d:
    Intent Screen2 = new Intent(Answer1.this, Color2.class); 
    Answer1.this.startActivity(Screen2);  
   break;


}
  • 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-13T02:09:31+00:00Added an answer on June 13, 2026 at 2:09 am

    When you want to write something to SharedPreferences use this

    SharedPreferences sharedPreferences = getSharedPreferences("your_name_of_shared_preferences", 0);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.clear();
    editor.putInt("result", resultValue);
    editor.commit();
    

    And to read something from them just do this

    SharedPreferences sharedPreferences = getSharedPreferences("your_name_of_shared_preferences", 0);
    int result = sharedPreferences.getInt("result", defaultValue);
    

    resultValue is your quiz result and defaultValue is needed in situation when you didn’t write anything to sharedPreferences under that key.

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

Sidebar

Related Questions

So I have this one quiz on my page, that tells the user what
There's an open book quiz for a job application I'm doing, and it's obviously
I have made a web application that administrate questions for a quiz. The web
I am doing a simple Quiz application that has several questions that the user
i have a module that needs to save a solution(for a quiz) value. This
I have a php file that writes to a txt file: <?php $answers =
I have this question in my online QUIZ since i am doing my degree
Basically I am doing a quiz app, I need to dedicate one question to
I have a pretty basic form that shows quiz questions along with choices: <%=
I am doing an Online Quiz project in C#. The test client is a

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.