intent

package veryedu.cls9.lession10.extra;


import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;


public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public  void   clickBtn(View view)
{
 if(view.getId()==R.id.btn1)
 {
 Intent intent=new Intent(this,SecondActivity.class);
 intent.putExtra("name", "张三");
 intent.putExtra("age",21);
 intent.putExtra("score", 78.5);
 
 Student stu=new Student();
 stu.setName("李四");
 stu.setAge(18);
 stu.setScore(95.5);
 intent.putExtra("stu",stu);
 
 startActivity(intent);
 
 }
}


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


}



package veryedu.cls9.lession10.extra;


import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.Toast;


public class SecondActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Intent intent=getIntent();
String name=intent.getStringExtra("name");
Bundle  bundle=intent.getExtras();
int age=bundle.getInt("age");
double score=bundle.getDouble("score");
Student stu=(Student)bundle.getSerializable("stu");

Toast.makeText(this, stu.toString(), Toast.LENGTH_LONG).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.second, menu);
return true;
}


}


package veryedu.cls9.lession10.extra;


import java.io.Serializable;


public class Student implements Serializable {
/**

*/
private static final long serialVersionUID = 1L;
private String name;
private int  age;
private double score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}

public String toString()
{
return  "姓名:"+name+" 年龄:"+age+" 分数"+score;
}


}


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="veryedu.cls9.lession10.extra"
    android:versionCode="1"
    android:versionName="1.0" >


    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="veryedu.cls9.lession10.extra.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="veryedu.cls9.lession10.extra.SecondActivity"
            android:label="@string/title_activity_second" >
        </activity>
    </application>


</manifest>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值