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. spring boot 事务支持

  2. hdu3189-Just Do It-(埃氏筛+唯一分解定理)

    Just Do It Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. Java happen-before

    下面是happens-before原则规则: 程序次序规则:一个线程内,按照代码顺序,书写在前面的操作先行发生于书写在后面的操作: 锁定规则:一个unLock操作先行发生于后面对同一个锁额lock操作 ...

  4. ADO.Net 数据库增加

    数据库增加数据其实就是把查询语句换成了增加语句,后面执行语句用操作变量点出一个执行方法 cmm.ExecuteNonQuery();//关键语句,执行CommandText,的SQL语句,增删改都用这 ...

  5. 2018面向对象程序设计(Java)第12周学习指导及要求

    2018面向对象程序设计(Java)第12周学习指导及要求 (2018.11.15-2018.11.18)   学习目标 (1) 掌握Java GUI中框架创建及属性设置中常用类的API: (2) 掌 ...

  6. JVM 图解--1.6,1.7,1.8

  7. CircleImageView of Android

    [CircleImageView of Android] github上有一个开源的圆角图片项目.地址:https://github.com/hdodenhof/CircleImageView 使用分 ...

  8. SQL Server 2008中SQL增强之一:Values新用途 001

    连接集合 select '1' as id,'wang' as name union select '2' as id,'admin' as name 现在可以这么写了 select id,name ...

  9. JMeter学习(七)聚合报告之 90% Line 正确理解(转载)

    转载自 http://www.cnblogs.com/yangxia-test 90% Line 参数正确的含义: 虽然,我的上面理解有一定的道理,显然它是错误的.那看看JMeter 官网是怎么说的? ...

  10. django通过添加session来保存公共变量

    有时候我们需要所有页面都使用同一个变量,比如用户登录信息.那不可能render每一个页面时都去传递一个变量,会非常麻烦 而用session可以解决这个问题   web的session可以通过reque ...