//----------Activity1中的布局---------------------------------

<LinearLayout 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"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/tv_text1"
        android:text="我是Activity1" />
    <EditText android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/et_edittext1"/>
    <Button android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="跳转到Activity2"
        android:id="@+id/bt_button1"/>

</LinearLayout>

//------------------Activity2的布局文件-------------------------------

<LinearLayout 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"
    android:orientation="vertical" >

     <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/tv_text2"
        android:text="我是Activity2" />
    <EditText android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/et_edittext2"/>
    <Button android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="跳转到Activity1"
        android:id="@+id/bt_button2"/>

</LinearLayout>

//---------------Activity1中-------------------------------

package com.example.test;

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.EditText;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

    private Button bt_button1;
    private TextView tv_text1;
    private EditText et_edittext1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv_text1 = (TextView) findViewById(R.id.tv_text1);
        et_edittext1 = (EditText) findViewById(R.id.et_edittext1);
        bt_button1 = (Button) findViewById(R.id.bt_button1);
        bt_button1.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.bt_button1:
            Intent intent=new Intent(this,TwoActivity.class);
            String text=et_edittext1.getText().toString().trim();
            intent.putExtra("kk", text);
            startActivityForResult(intent, 0);
            break;

        default:
            break;
        }
        
    }
    //此方法用户接受返回的数据
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (resultCode) {
        case 1:
            Bundle b=data.getExtras();
            String str=b.getString("ww");
            tv_text1.setText(str);
            break;

        default:
            break;
        }
        
    }

    
    
}

//----------------Activity2中----------------------------

package com.example.test;

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.EditText;
import android.widget.TextView;

public class TwoActivity extends Activity implements OnClickListener {

    private TextView tv_text2;
    private EditText et_edittext2;
    private Button bt_button2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);
        //找到控件
        tv_text2 = (TextView) findViewById(R.id.tv_text2);
        et_edittext2 = (EditText) findViewById(R.id.et_edittext2);
        bt_button2 = (Button) findViewById(R.id.bt_button2);
        //获得Activity1传递来的值
        Intent intent=getIntent();
        String str=intent.getStringExtra("kk");
        //显示Activity1传递来的值
        tv_text2.setText(str);
        
        
        bt_button2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.bt_button2:
            String text=et_edittext2.getText().toString().trim();
            Intent intent=new Intent(this,MainActivity.class);
            intent.putExtra("ww", text);
            //用setResult返回数据
            setResult(1, intent);
            finish();
            break;

        default:
            break;
        }
        
    }

    

}

Activity与Activity之间的传值的更多相关文章

  1. android:两个应用之间怎样传值之activity

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/zjh171/article/details/37738579 两个应用之间怎样传值.事实上这个标题太 ...

  2. Android Activity的四种经典传值方法

    文/ http://blog.csdn.net/sk719887916/article/details/41723613  skay 开发中遇到多个activity的传值问题 相邻两个之间的传值 或者 ...

  3. activity与fragment之间的传递数据

    首先activity之间的数据传递就是 用intent和intent+bundle intent 传递 Intent i= new Intent(MainActivity.this,TheAty.cl ...

  4. Android课程---Activity的跳转与传值(转自网上)

    Activity跳转与传值,主要是通过Intent类来连接多个Activity,以及传递数据.   Intent是Android一个很重要的类.Intent直译是“意图”,什么是意图呢?比如你想从这个 ...

  5. Activity的跳转与传值(转载)

    Activity跳转与传值,主要是通过Intent类来连接多个Activity,以及传递数据.   Intent是Android一个很重要的类.Intent直译是“意图”,什么是意图呢?比如你想从这个 ...

  6. Activity与Fragment之间的通信

    由于Fragment的生命周期完全依赖宿主Activity,所以当我们在使用Fragment时难免出现Activity和Fragment间的传值通信操作. 1.Activity向Fragment,通过 ...

  7. Activity和Fragment之间解耦

    看鸿洋博客:http://blog.csdn.net/lmj623565791/article/details/42628537,整理下一些关键点 public class ContentFragme ...

  8. Activity与Service之间交互并播放歌曲的实现代码

    Activity与Service之间交互并播放歌曲,为了方便,我把要播放的歌曲定死了,大家可以灵活改进 MService: 复制代码代码如下: package com.tiantian.test;im ...

  9. Activity的跳转与传值

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://android.blog.51cto.com/268543/323982 Acti ...

  10. activity与service之间的通信方式

    Activity之间的通信 1.activity与activity的通信可以通过Intent来封装数据,startActivityForResult()来实现,当跳转的activity调用finish ...

随机推荐

  1. java中的字符编码方式

    1. 问题由来 面试的时候被问到了各种编码方式的区别,结果一脸懵逼,这个地方集中学习一下. 2. 几种字符编码的方式 1. ASCII码 我们知道,在计算机内部,所有的信息最终都表示为一个二进制的字符 ...

  2. lucene索引的创建与搜索

    package com.cs.multi; import java.io.File;import java.io.IOException; import org.apache.lucene.analy ...

  3. The server instance Witness rejected configure request; read its error log file for more information. The reason 1427, and state 31, can be of use for

    数据库服务器做了镜像之后,发现有错误信息 The server instance Witness rejected configure request; read its error log file ...

  4. YaHoo Web优化的14条法则

    Web应用性能优化黄金法则:先优化前端程序(front-end)的性能,因为这是80%或以上的最终用户响应时间的花费所在. 法则1. 减少HTTP请求次数 80%的最终用户响应时间花在前端程序上,而其 ...

  5. DPI与PPI

    首先应该明白几个概念: 1寸=3.3333333厘米(cm)1英寸(in)=2.54厘米(cm)屏幕尺寸: 屏幕对角线的长度.电脑电视同理.LCD是由液态晶体组成的显示屏(本向不发光) 有于电脑手机显 ...

  6. 自定义Button成进度条

    ProgressButton源码: package com.example.progressbutton; import android.content.Context; import android ...

  7. Linux Ubuntu 14.04安装LAMP(Apache+MySQL+PHP)网站环境

    从虚拟主机到VPS/服务器的过度,对于普通的非技术型的站长用户来说可能稍许有一些困难,麦子建议我们如果能够在虚拟主机环境中满足建站需要的, 还是用虚拟主机比较好.除非我们真的有需要或者希望从虚拟主机过 ...

  8. 解决centos网速特别慢的最佳解决办法

    摘自:http://www.centoscn.com/CentosBug/osbug/2014/0614/3138.html 我使用了centOS,但是发现网速实在是卡得几乎不能上网,连百度都打不开, ...

  9. Java 环境搭建的一些问题

    1.http://www.eclipse.org/webtools/  eclipse 官网,SE.EE方向是两个不同eclipse 2.tomcat 对eclipse来说是一个插件,需要额外下载 T ...

  10. Hadoop YARN ERROR 1/1 local-dirs are bad *, 1/1 log-dirs are bad *

    转 http://blog.csdn.net/u012303571/article/details/46913471   查看 nodemanager 日志发下 如下信息   2015-07-16 1 ...