You have to edit only the code segment appear in bold font.
Source code for First.java
Source code for Second.java
Source code for first_layout.xml
Source code for second_layout.xml
Source code for strings.xml
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; @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"); 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); 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(); } }); }} |
Source code for first_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".First" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/bn" android:text="NEXT ACTIVITY" android:layout_centerInParent="true" /> </RelativeLayout> |
Source code for second_layout.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="horizontal" > <EditText android:layout_width="150dp" android:layout_height="wrap_content" android:id="@+id/text" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/bn" android:text="@string/bnname" /> </LinearLayout> |
Source code for strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">SecondApp</string> <string name="hello_world">Hello world!</string> <string name="menu_settings">Settings</string> <string name="bnname">Submit</string> </resources> |
Source code for AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.easyway2in" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.easyway2in.First" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Second" android:label="@string/app_name" > <intent-filter> <action android:name="com.easyway2in.Second" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> </manifest> |
Comments
Post a Comment