How to get the content that user type in a EditText field in one Activity to another Activity in Android

In this blog post you can learn how to get the content that user type in a EditText field in one Activity to another Activity in Android.

Below you can see the “FormActivity” interface.

FormActivity interface

We want to pass the content that user type in the EditText field as in image2 to another Activity called “WelcomeActivity” (image3)

input for FormActivity

WelcomeActivity

We can do it under the click event of the “buttonOk” in “FormActivity” as follow.


        buttonOk.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				String name = editTextName.getText().toString(); //get the text that the user type		

				Intent intent = new Intent(FormAvtivity.this, WelcomeActivity.class);

				// Passing a Bundle object to another Activity
				Bundle bundle = new Bundle();
				bundle.putString("msg", name);
				intent.putExtras(bundle);

				startActivity(intent);				
			}
		});


The next thing we have to do is get above passed data and show them under “WelcomeActivity” as follow.


		Bundle b = getIntent().getExtras(); // Getting the Bundle object that pass from another activity
		String msg = b.getString("msg");

		editTextWelcome.setText(msg);


That is it 🙂

Advertisements

About AnujAroshA

Working as a Senior Software Engineer. Specialized in iOS application development. A simple person :)
This entry was posted in Android Examples. Bookmark the permalink.

10 Responses to How to get the content that user type in a EditText field in one Activity to another Activity in Android

  1. Babu says:

    Hai anujarosha,

    Your article is nice. But I need Simple Insert, Delete,Update Datas in android SQLiteDatabase.Plsssss…..
    babugac07@gmail.com