![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button1"
/>
</LinearLayout>
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
package com.Neddy;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity
{
private Button button=null;
private final static int REQUEST_CODE=1;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button=(Button)findViewById(R.id.button1);
button.setOnClickListener(listener);
}
private OnClickListener listener=new OnClickListener()
{
public void onClick(View v)
{
// Intent intent=new Intent();
// intent.setAction(Intent.ACTION_SENDTO);
// intent.setData(Uri.parse("smsto:5554"));
// intent.putExtra("sms_body", "Welcome to ...");
// startActivity(intent);
Intent intent=new Intent();
intent.setClass(MainActivity.this,SecondActivity.class);
intent.putExtra("str", "HI,hello world!");
// startActivity(intent);
startActivityForResult(intent, REQUEST_CODE);
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode==REQUEST_CODE)
{
if(resultCode==SecondActivity.RESULT_CODE)
{
Bundle bundle=data.getExtras();
String str=bundle.getString("back");
Toast.makeText(MainActivity.this,str,Toast.LENGTH_LONG).show();
}
}
}
}
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
package com.Neddy;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class SecondActivity extends Activity
{
private TextView second=null;
private Button button2=null;
final static int RESULT_CODE=1;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
Intent intent=getIntent();
Bundle bundle=intent.getExtras();
String str=bundle.getString("str");
second=(TextView)findViewById(R.id.second);
second.setText(str);
button2=(Button)findViewById(R.id.button2);
button2.setOnClickListener(listener);
}
private OnClickListener listener=new OnClickListener()
{
public void onClick(View v)
{
Intent intent=new Intent();
intent.putExtra("back", "Back Data");
setResult(RESULT_CODE,intent);
finish();
}
};
}
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Neddy"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
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=".SecondActivity"
android:label="Second">
</activity>
</application>
<uses-permission android:name="android.permission.SEND_SMS"/>
</manifest>