AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hanqi.test4"> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main2Activity"></activity>
</application> </manifest>

MainActivity

package com.hanqi.test4;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast; /**
* Created by Administrator on 2016/3/21.
*/
public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.main_layout); }
//普通方式
public void ONCLICK(View v)
{
Log.e("T4TAG","按钮的点击监听被触发");
//静态方法
//直接用类名就可以调用,不需要实例化
//构建了一个Toast实例
//方法连
Toast.makeText(this,"按钮的点击监听被触发",Toast.LENGTH_LONG).show(); // Toast toast= Toast.makeText(this,"按钮的点击监听被触发",Toast.LENGTH_LONG);
// toast.show(); //用intent //取得要传递的信息
//获取View实例
EditText myet=(EditText)findViewById(R.id.myet); String string= myet.getText().toString(); Intent intent= new Intent(this,Main2Activity.class);
//存储内容
//getExtra Bundle 实际是一个HashMap 进行了限制
//intent.getExtras().putString("myet",string);
intent.putExtra("myet",string); startActivity(intent);
}
//带返回的方式 public void onCLICK(View v)
{
EditText myet=(EditText)findViewById(R.id.myet); String string= myet.getText().toString(); Intent intent= new Intent(this,Main2Activity.class);
//存储内容
//getExtra Bundle 实际是一个HashMap 进行了限制
//intent.getExtras().putString("myet",string);
intent.putExtra("myet",string);
//有返回数据的启动方式
//第一个参数 intent
//第二个参数 requestCode 请求码
startActivityForResult(intent, 1);
}
//重写 处理返回信息的监听(回调方法)
//onActivityResult通用监听 监听所有返回信息的
//必须要有requestCode区分有哪个请求返回的
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); Log.e("TAG","requestCode="+requestCode+"resultCode"+resultCode);
if (requestCode ==1 )
{
if (resultCode == RESULT_OK)
{
//获取返回信息
String string = data.getExtras().getString("mytv"); EditText editText =(EditText)findViewById(R.id.myet); editText.setText(string);
Toast.makeText(this, "返回信息=" + string, Toast.LENGTH_LONG);
}
else {
Toast.makeText(this,"返回信息有问题",Toast.LENGTH_SHORT);
}
} }
}

main_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/myet"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通方式"
android:onClick="ONCLICK"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="带返回方式"
android:onClick="onCLICK"
/>
</LinearLayout>

Main2Activity

package com.hanqi.test4;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText; public class Main2Activity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2); //接受信息
//获取意图
//传递过来的Intent
Intent intent=getIntent(); String s = intent.getExtras().getString("myet"); EditText mytv=(EditText)findViewById(R.id.mytv); mytv.setText(s);
}
//普通返回
public void onclick(View V)
{
//关闭当前activity
finish();
}
public void ONclock(View v)
{
//存储返回数据 也要用intent
EditText mytv=(EditText)findViewById(R.id.mytv);
Bundle bundle =new Bundle();
bundle.putString("mytv",mytv.getText().toString()); //设置返回数据
// 先设置ReaultCode,再设置存储数据的意图
setResult(RESULT_OK,new Intent().putExtra("mytv",mytv.getText().toString()));
//关闭当前activity
finish();
}
}

activity_main2.xml

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.hanqi.test4.Main2Activity"> <EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="测试" android:id="@+id/mytv"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通返回"
android:onClick="onclick"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="带数据返回"
android:onClick="ONclock"
/>
</LinearLayout>

android--Activity有返回值的跳转的更多相关文章

  1. Android课程---Activity 带返回值的跳转

    Activity2.java package com.hanqi.test4; import android.content.Intent; import android.os.Bundle; imp ...

  2. 【Android】12.3 在当前Activity中获取另一个Activity的返回值

    分类:C#.Android.VS2015: 创建日期:2016-02-23 一.简介 在上一节的示例中,通过StartActivity(Intent)方法启动另一个Activity后,这两个Activ ...

  3. activity 接回返回值

    activity 接回返回值 今天做订单列表显示 点击某一项显示订单详细信息,在详细activity中用户可以选择取消订单(未支付的状态下)当用户取消订单后订单列表也要改变状态,原来最初做法是所加载绑 ...

  4. android 16 带返回值的activity

    main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" andro ...

  5. Android - 和其他APP交互 - 获得activity的返回值

    启用另一个activity不一定是单向的.也可以启用另一个activity并且获得返回值.要获得返回值的话,调用startActivityForResult()(而不是startActivity()) ...

  6. Android checkCallingPermission()方法返回值问题

    Android开发检查权限时,发现调用checkCallingPermission()总是返回值-1,而Binder.getCallingPid() == Process.myPid()又总是返回tr ...

  7. [android] setOnTouchEvent 设置返回值为true 和 false的区别

    今天在做自定义的可选文本的 TextView 类时,用到了 View 类的 setOnTouchListener(OnTouchListener l)事件监听,在构造 OnTouchListener ...

  8. phonegap android插件,启动activity并返回值

    Your execute menthod is not quite right. When you do: return new PluginResult(PluginResult.Status.OK ...

  9. 【Python web自动化】之读取配置文件参数,利用cookie返回值进行跳过验证码进行登录操作

    当进行Python的Web自动化时,会涉及到验证码问题,该如何跳过执行呢,下面请看代码: 1.首先新建配置文件*.ini格式 config.ini [db] #基础地址: baseurl = http ...

随机推荐

  1. windows7 IIS7报错:如果要使用托管的处理程序,请安装 ASP.NET

    IIS7报错:如果要使用托管的处理程序,请安装 ASP.NET windows7,部署在本地的IIS7里以后,结果不能访问承载SL的.aspx页面,而如果用.html承载则可以访问. 亲测可用修复办法 ...

  2. tensorflow降低版本

    tensorflow降低版本: pip install tensorflow==1.2.0 查看版本: import tensorflow as tf print(tf.__version__)

  3. 机器学习之overfiting

    有错欢迎指正,别让小弟继续错下去. 我们在使用机器学习过程中,经常会overfiting,overfiting的产生原因是noise.训练样本大的话,还好,不用考虑这个 问题.但是,当数据量小的时候, ...

  4. 定时删除文件夹"$1"下最后修改时间大于当前时间"$2"天的文件

    shell 脚本: #!/bin/bash now=`date "+%Y-%m-%d_%H:%M:%S"`      #获取当前时间 echo "当前时间: " ...

  5. Java多线程及线程状态转换

    以下内容整理自:http://blog.csdn.net/wtyvhreal/article/details/44176369 线程:是指进程中的一个执行流程.  线程与进程的区别:每个进程都需要操作 ...

  6. java中File类的常用方法总结

    java中File类的常用方法 创建: createNewFile()在指定的路径创建一个空文件,成功返回true,如果已经存在就不创建,然后返回false. mkdir() 在指定的位置创建一个此抽 ...

  7. vmware 共享文件夹

    参考 https://jingyan.baidu.com/article/7f766daf7866be4101e1d0ed.html 只是设置共享文件夹选项还不行,需要从安装vmware的安装路径中找 ...

  8. jenkins权限控制

    一.插件安装 插件:Role-based Authorization Strategy版本:2.3.2 二.全局安全配置 进入Jenkins后点击系统管理进入全局安全配置 当插件安装好的时候,授权策略 ...

  9. 15. 3Sum (重新分配数组大小)

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...

  10. <asp:Button点击查询后,调用js中函数展现加载圈

    <div> <div id='paneloading' style='display:none;position:fixed;top:0px;left:0px;z-index:999 ...