Watch video Tutorial of this Topic
You have to edit only the code segment show in bold font.
Source code for First.java
package com.easyway2in; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class First extends Activity { Button button; int request_code; Bundle extras; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.first_layout); request_code=1; button = (Button) findViewById(R.id.bn) ; button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent i = new Intent("com.easyway2in.Second"); extras = new Bundle(); extras.putString("hintkey", "Enter text here"); i.putExtras(extras); startActivityForResult(i, request_code); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.first_layout, menu); return true; } public void onActivityResult(int requestcode, int resultcode, Intent data) { if(request_code==requestcode) { if(resultcode==RESULT_OK) { Toast.makeText(getBaseContext(),data.getData().toString(), Toast.LENGTH_SHORT).show(); } } } } |
Source code for Second.java
package com.easyway2in; import org.w3c.dom.Text; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class Second extends Activity{ Button bn; EditText txt; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.second_layout); bn = (Button) findViewById(R.id.bn); txt = (EditText) findViewById(R.id.text); Bundle extras = getIntent().getExtras(); String value = extras.getString("hintkey"); txt.setHint(value); bn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent data = new Intent(); String value = txt.getText().toString(); data.setData(Uri.parse(value)); setResult(RESULT_OK, data); finish(); } }); } } |
All the other files are same as in the previous part.