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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:21:46+00:00 2026-06-01T20:21:46+00:00

I want to sent intent from one first activity to another. The first activity

  • 0

I want to sent intent from one first activity to another.

The first activity sends an intent to the second activity in order to create a new AlertDialog, receive a number from the user and send the number back to the first activity, that’s where putExtra data to failed.

The code of the first activity: GuessItActivity.java

                    Intent intent = new Intent(GuessItActivity.this,
                        AlertDialogMessage.class);
                intent.addFlags(Intent.FILL_IN_DATA);
                intent.addFlags(Intent.FILL_IN_CATEGORIES);
                intent.addFlags(Intent.FILL_IN_ACTION);
                
                intent.putExtra("data1", 15);
                startActivityForResult(
                        intent,
                        getResources().getInteger(
                                R.integer.ALERT_DIALOG_MESSAGE));

on the retriever side , e.g the second activity side on AlertDialogMessage.java

                            public void onClick(DialogInterface dialog,
                                int which) {
                            // "OK" button pressed
                            int userGuess = Integer.parseInt(input
                                    .getText().toString());
                            Intent intent = getIntent();
                            if (intent == null)
                                return;

                            int data1 = intent.getIntExtra("data1", -1);
                            if (data1 != 15 )
                                return; // data1 ==15 
                            
                            intent.putExtra("data2", 25);           
                            if (getParent() == null) {
                                setResult(Activity.RESULT_OK, intent);
                            } else {
                                getParent().setResult(Activity.RESULT_OK,
                                        intent);
                            }
                            finish();

The first activity side: back to GuessItActivity.java

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == getResources().getInteger(
            R.integer.ALERT_DIALOG_MESSAGE)) {
        if (resultCode == RESULT_OK) {
            Intent intent = getIntent();
            if (intent==null)
                return; 


              Bundle extra = getIntent().getExtras();
            if (extra != null) {
                int _data1 = extra.getInt("data1");
                int _data2 = extra.getInt("data2");
            }
               // extra  == null , what am I doing wrong  ? 

            int data1 = intent.getIntExtra("data1",-1);
            int data2 = intent.getIntExtra("data2",-1);
            if ((data1==-1)&&(data1==-1))
                return; 

The problem is , that I receive data1 and data2 equal to -1.

I’d like to receive the data the I put on the second activity. e.g data1 == 15 and data2 == 25

What am I doing wrong?

  • 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-01T20:21:47+00:00Added an answer on June 1, 2026 at 8:21 pm

    Try

    Bundle extra=data.getExtras();
    

    Insted of

    Bundle extra=getIntent().getExtras();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a logger which logs all my messages sent to System.out
My first activity is creating a second activity within its onCreate: if (userName ==
What I want is that when Activity starts first time, it first checks if
I'm creating a CMS, and want all request sent to Default.aspx except for the
I want to shrink the data that is sent back and forth via AJAX,
I want to have my pdf files sent this way to my users :
I want to see the actual commands sent to g++ during a Code::Blocks build.
I want to use vba to take a screenshot (which will then be sent
So I want to make a HTML news letter to be sent out. I
I just want to intercept raw data (hex)--headers and all--sent to a port, and

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.