android 通过activity返回数据

  • 内容
  • 评论
  • 相关

MainActivity

package com.example.clipboard;


import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity{

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

	@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;
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case 1:
			switch (resultCode) {
			case 2:
				setTitle(data.getStringExtra("key01"));
				break;

			default:
				break;
			}
			break;

		default:
			break;
		}
	}

	public void onClick_StartAnother(View view){
		Intent intent = new Intent(this,MainActivity01.class);
		startActivityForResult(intent, 1);
	}
}

MainActivity01

package com.example.clipboard;


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

public class MainActivity01 extends Activity {
	private EditText myEdittext;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_activity01);
		
		myEdittext = (EditText) findViewById(R.id.edittext);
	}

	@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_activity01, menu);
		return true;
	}

	public void onClick_Button(View view){
		String myTitle = myEdittext.getText().toString();
		Intent intent = new Intent();
		intent.putExtra("key01", myTitle);
		setResult(2,intent);
		finish();
	}
}

完整项目文件地址
http://pan.baidu.com/s/1bnpaWEF

评论

0条评论

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注