Activity

package com.example.activity2;

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

public class MainActivity extends Activity {

	int page=0;
	TextView tv_show;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		page = 40;
		if(savedInstanceState!=null){
			System.out.println("当前页为:"+savedInstanceState.getInt("page"));
		}
		tv_show = (TextView) this.findViewById(R.id.tv_show);
		
	}

	public void on(View view){
		switch (view.getId()) {
		case R.id.btn_1:
			Intent intent = new Intent();
			//intent.setClass(this, OtherActivity.class);
			//intent.setClassName("com.example.activity2", "com.example.activity2.OtherActivity");
			
			//intent.setAction("android.intent.action.CALL");
			//intent.setData(Uri.parse("tel://10086"));
			//intent.setAction("android.intent.action.VIEW");
			//intent.setData(Uri.parse("http://www.baidu.com"));
			
			//intent.setAction("android.intent.action.VIEW");
			//intent.setDataAndType(Uri.parse("file:///mnt/sdcard/1.mp3"),"audio/*");
			//intent.setAction("android.intent.action.VIEW");
			//intent.setDataAndType(Uri.parse("file:///mnt/sdcard/1.jpg"),"image/*");
			
			/*Bundle bundle1 = new Bundle();
			bundle1.putString("name", "aa");
			bundle1.putInt("age", 1);
			Bundle bundle2 = new Bundle();
			bundle2.putString("name", "bb");
			bundle2.putInt("age", 2);
			intent.setClass(this, OtherActivity.class);
			intent.putExtra("bundle1",bundle1);
			intent.putExtra("bundle2",bundle2);*/
			
			Person p1 = new Person("aa",11);
			Person p2 = new Person("bb",22);
			intent.setClass(this,OtherActivity.class);
			intent.putExtra("person1", p1);
			intent.putExtra("person2", p2);

			
			Person p3 = new Person("cc",33);
			intent.setClass(this, OtherActivity.class);
			intent.putExtra("person1", p3);
			startActivityForResult(intent, 100);
			
			
			
			break;

		default:
			break;
		}
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if(requestCode==100 && resultCode==100){
			Person p1 = (Person) data.getSerializableExtra("person3");
			tv_show.setText(p1.getName()+":"+p1.getAge());
		}
		
		
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		
		super.onSaveInstanceState(outState);
		outState.putInt("page", page);
	}

}


package com.example.activity2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class OtherActivity extends Activity {

	Button btn_close;
	TextView tv_show;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_other);
		tv_show = (TextView) this.findViewById(R.id.othershow);
		/*Intent intent = getIntent();
		Bundle data1 = intent.getBundleExtra("bundle1");
		String name1 = data1.getString("name");
		int age1 = data1.getInt("age");
		Bundle data2 = intent.getBundleExtra("bundle2");
		String name2 = data2.getString("name");
		int age2 = data2.getInt("age");
		tv_show.setText(name1+":"+age1+";"+name2+":"+age2);*/
		
		Intent intent = getIntent();
		Person p1 = (Person) intent.getSerializableExtra("person1");
		String name1 = p1.getName();
		int age1 = p1.getAge();
		Person p2 = (Person) intent.getSerializableExtra("person2");
		String name2 = p2.getName();
		int age2 = p2.getAge();
		tv_show.setText(name1+":"+age1+";"+name2+":"+age2);
		
		
	}
	
	public void on(View view){
		switch (view.getId()) {
		case R.id.otherclose:
			Intent data = new Intent();
			Person p3 = new Person("dd",44);
			data.putExtra("person3", p3);
			setResult(100, data);
			OtherActivity.this.finish();
			
			break;

		default:
			break;
		}
	}
}

package com.example.activity2;

import java.io.Serializable;

public class Person implements Serializable{

	private String name;
	private int age;
	
	public Person(){
		
	}
	
	public Person(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}
	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;
	}
	
	
}

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

    <uses-permission android:name="android.permission.CALL_PHONE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="com.example.activity2.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.CALL" />
                <action android:name="android.intent.action.VIEW" />
                <data android:scheme="tel" />
                <data android:scheme="http" />
                <data android:scheme="file" android:mimeType="audio/*" />
                <data android:scheme="file" android:mimeType="video/*" />
                <data android:scheme="file" android:mimeType="image/*" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.activity2.OtherActivity"
            android:label="@string/title_activity_other" >
        </activity>
    </application>

</manifest>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值