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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:58:36+00:00 2026-06-05T23:58:36+00:00

I am trying to use the getIntent value(score) which is retrieve from the previous

  • 0

I am trying to use the getIntent value(score) which is retrieve from the previous activity but it seems like it is impossible. It seems that addition and subtraction under if else cannot detect score. Is there any other way?

package com.mkyong.android;

import com.mkyong.android.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View;
import android.view.View.OnClickListener;

public class App2Activity extends Activity {

    private RadioGroup radioAnswerGroup2;
    private RadioButton radioAnswerButton2;
    private Button btnSubmit2;

    Button button2;


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


    }

    public void addListenerOnButton() {

        final Context context = this;

        radioAnswerGroup2 = (RadioGroup) findViewById(R.id.radioAnswer2);


        button2 = (Button) findViewById(R.id.button2);
        Button button2pre = (Button) findViewById(R.id.button2pre);

        Intent intent = getIntent();
        final int score = intent.getIntExtra("int", -1);
        final TextView result2 = (TextView) findViewById(R.id.txtResult2);
        result2.setText("Result counting: " + String.valueOf(score));


        button2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


                int correctId2 = (R.id.answer2b);

                // get selected radio button from radioGroup
                int selectedId2 = radioAnswerGroup2.getCheckedRadioButtonId();

                // find the radio button by returned id
                radioAnswerButton2 = (RadioButton) findViewById(selectedId2);

                if (selectedId2==correctId2){

                     score = score + 1;
                    //show toast saying it is correct
                    //Context context = getApplicationContext();
                    //CharSequence text = ("You are correct!");
                    //int duration = Toast.LENGTH_SHORT;

                    //Toast toast = Toast.makeText(context, text, duration);
                    //toast.show();
                }
                else{

                    score = score - 1;
                    //toast incorrect
                    //Context context = getApplicationContext();
                    //CharSequence text = ("You are wrong but it's ok and the answer is Data Link");
                    //int duration = Toast.LENGTH_LONG;

                    //Toast toast = Toast.makeText(context, text, duration);
                    //toast.show();
                }   

                Intent intent2 = new Intent(App2Activity.this, App3Activity.class);
                intent2.putExtra("int", score); 
                startActivity(intent2);  

            }

        });


        button2pre.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(context, AppActivity.class);
                startActivity(intent);   

            }

        });


    }

}
  • 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-05T23:58:37+00:00Added an answer on June 5, 2026 at 11:58 pm

    Move int score to be a global variable to access it in onClick. You’ll also need to remove the final keyword so the value can be changed after you initialize it.

     public class YourActivity extends Activity{
    
           int score;
    
          public onCreate( /*...etc.*/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use JSON and HTTP client to retrieve data from a
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
trying to use this route: from(activemq:profiles).aggregate(header(cheese)).batchSize(30).bean(ProfilesQueueService, saveContacts) Fails with: No signature of method: org.apache.camel.model.RouteType.aggregate()
I am trying to retrieve the values from the following url: http://rentopoly.com/ajax.php?query=Bo . I
I'm trying to get data from website which is encoded in UTF-8 and insert
I am currently trying to use JavaMail to get emails from IMAP servers (Gmail
I am trying to store the value of the GPS coordinates that are in
I am trying to use the 2nd value of each of my JSON elemnts
I'm trying to use a SAX parser to parse a HTTP response. Everything seems

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.