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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:18:26+00:00 2026-06-11T07:18:26+00:00

i actually take this code form vogella.com . i want to pass the data

  • 0

i actually take this code form vogella.com.

i want to pass the data from the second activity to first activity when click the button in second activity. to make sure the value passing is correct, i want it display as a toast when going back to first activity.

this is my code on the firstactivity_layout. res/activity_intentintent.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minHeight="60dip"
        android:text="First Activity. Press button to call second activity"
        android:textSize="20sp" >
    </TextView>

    <Button
        android:id="@+id/Button01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClick"
        android:text="Calling an intent" >
    </Button>

</LinearLayout> 

this is the second code for layout. res/picklayout.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >



    <EditText
        android:id="@+id/input11"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" >

        <requestFocus />
    </EditText>



    <EditText
        android:id="@+id/input22"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />


    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

</LinearLayout>

this is the activity code for the first layout, IntentintentActivity.java

public class IntentintentActivity extends Activity {
    Button btn1;
    private static final int REQUEST_CODE = 10;

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

    }

    public void onClick(View view) {
        Intent i = new Intent(this, PickActivity.class);
        i.putExtra("Value1", "This value one for ActivityTwo ");
        i.putExtra("Value2", "This value two ActivityTwo");
        // Set the request code to any code you like, you can identify the
        // callback via this code
        startActivityForResult(i, REQUEST_CODE);
      }

      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
          if (data.hasExtra("returnKey1")) {
            Toast.makeText(this, data.getExtras().getString("returnKey1"),
                Toast.LENGTH_SHORT).show();
          }
        }
      }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_intentintent, menu);
        return true;
    }

and the last is the second activity, PickActivity.java

public class PickActivity extends Activity{ 
Button submit;
EditText text1, text2;

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
        setContentView(R.layout.picklayout);

        Bundle extras = getIntent().getExtras();
        if (extras == null) {
          return;
        }
        String value1 = extras.getString("Value1");
        String value2 = extras.getString("Value2");
        if (value1 != null && value2 != null) {
          text1 = (EditText) findViewById(R.id.input11);
          text2 = (EditText) findViewById(R.id.input22);
          text1.setText(value1);
          text2.setText(value2);            

        }   
        submit = (Button)findViewById(R.id.button1);
        /*
        submit.setOnClickListener(new OnClickListener(){
            public void onClick(View v){
                Toast.makeText(this, text1.getText(), 2500).show();
            }
        });
        */
    }

public void onClick(View v) {
    Toast.makeText(this, text1.getText(), 2500).show();
    finish();
  }     

      @Override
      public void finish() {
        Intent data = new Intent(this, IntentintentActivity.class);
        Toast.makeText(this, "finish state", 2500).show();
        // Return some hard-coded values
        data.putExtra("returnKey1", "Swinging on a star. ");
        data.putExtra("returnKey2", "You could be better then you are. ");
        setResult(RESULT_OK, data);
        int result = 1;
        //startActivityForResult(data, result);
        super.finish();
      }

}

i tried to put listener for the button in the second activity like this.

public class PickActivity extends Activity{ 
Button submit;
EditText text1, text2;

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
        setContentView(R.layout.picklayout);

        Bundle extras = getIntent().getExtras();
        if (extras == null) {
          return;
        }
        String value1 = extras.getString("Value1");
        String value2 = extras.getString("Value2");
        if (value1 != null && value2 != null) {
          text1 = (EditText) findViewById(R.id.input11);
          text2 = (EditText) findViewById(R.id.input22);
          text1.setText(value1);
          text2.setText(value2);            

        }   
        submit = (Button)findViewById(R.id.button1);

        submit.setOnClickListener(new OnClickListener(){
            public void onClick(View v){
                Toast.makeText(this, text1.getText(), 2500).show();
            }
        });

    }

however it said Toast.makeText(...) is not applicable for the argument(new View.onClickListener).

does anyone know how to solve this please. thank you.

  • 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-11T07:18:27+00:00Added an answer on June 11, 2026 at 7:18 am

    In your Toast you have to replace ‘this’ argument with getBaseContext()

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

Sidebar

Related Questions

I want to take a snapshot from a webcam through java. I followed this
Could someone take a look at this code and find out what's wrong with
The first time I open one of my child forms from the main form
I have the following code: <button data-dojo-type=dijit.form.Button data-dojo-props='baseClass:styleButton' name=_action_update type=submit label=Save >Save</button> The problem
Actually I have to take the sequence number in $Revisions field.
Actually I am developing one application in that when application run first time it
Actually I am working on this for the last 3 or 4 weeks but
Actually I am stuck in middle of some mysql code. Can anyone suggest a
Actually i want that, suppose i have a colorcode #FF3366. How can i examine
Actually ,i am working on a livechat application its works fine.This application is tabbed

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.