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. C++与java编程区别(一)

    转载自http://blog.sina.com.cn/s/blog_75f4e17c0101295o.html C++ HelloWorld main.cpp #include< iostrea ...

  2. 拓扑排序-有向无环图(DAG, Directed Acyclic Graph)

    条件: 1.每个顶点出现且只出现一次. 2.若存在一条从顶点 A 到顶点 B 的路径,那么在序列中顶点 A 出现在顶点 B 的前面. 有向无环图(DAG)才有拓扑排序,非DAG图没有拓扑排序一说. 一 ...

  3. 三种方式解决你的js加载乱码

    第一种方式——编码统一 我们以前觉得出现乱码的原因是因为编码不统一,就是因为我们设置编码统一之后,就解决了问题,所以,让html和js的编码统一,是最简单的一个乱码解决方式,原因是什么,是因为,如果你 ...

  4. 环境变量之path的一点理解

    最初安装java环境时一直不明白为什么要配置环境变量,百度了一下还是理解不透彻. 后来安装python时也要配置环境变量.. 在经过未配置和配置的操作后,才有些理解path的含义. 1.未配置环境变量 ...

  5. JDK1.8 HashMap 扩容 对链表(长度小于默认的8)处理时重新定位的过程

    关于HashMap的扩容过程,请参考源码或百度. 我想记录的是1.8 HashMap扩容是对链表中节点的Hash计算分析. 对术语先明确一下: hash计算指的确定节点在table[index]中的链 ...

  6. CRTD异常案例及原因

     错误案例: SELECT DEMANDLINEID,SUPPLYORDERID,DEMANDORDERID,QTYALLOCATED,ITEM, A.* FROM ABPPMGR.SUPPLYDMD ...

  7. Android学习路-UI控件

  8. 关于OPEN_MAX宏undeclared的问题

    最近在看unp时,I/O复用-poll一章的代码使用到了OPEN_MAX.据书中描述,这一宏定义在limits.h头文件中,指代一个进程在任意时刻能打开的最大描述符数目.但在代码编译时遇到了错误,提示 ...

  9. avcodec_decode_video2少帧问题

    使用libav转码视频时发现一个问题:使用下面这段代码解码视频时,解码中会不时丢掉几帧. ){ ret = avcodec_decode_video2(video_dec_ctx, vframe, & ...

  10. Hudson 打包部署到Was上特别慢

    一.找问题点 1.打包很快,到部署很慢 2.部署到其他was一样很慢 二.解决 经过寻找,网上找出以下一段话: 问题出在web.xml,web.xml中的版本信息不对,要根据你的servlet版本和运 ...