android--Activity有返回值的跳转
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有返回值的跳转的更多相关文章
- Android课程---Activity 带返回值的跳转
Activity2.java package com.hanqi.test4; import android.content.Intent; import android.os.Bundle; imp ...
- 【Android】12.3 在当前Activity中获取另一个Activity的返回值
分类:C#.Android.VS2015: 创建日期:2016-02-23 一.简介 在上一节的示例中,通过StartActivity(Intent)方法启动另一个Activity后,这两个Activ ...
- activity 接回返回值
activity 接回返回值 今天做订单列表显示 点击某一项显示订单详细信息,在详细activity中用户可以选择取消订单(未支付的状态下)当用户取消订单后订单列表也要改变状态,原来最初做法是所加载绑 ...
- android 16 带返回值的activity
main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" andro ...
- Android - 和其他APP交互 - 获得activity的返回值
启用另一个activity不一定是单向的.也可以启用另一个activity并且获得返回值.要获得返回值的话,调用startActivityForResult()(而不是startActivity()) ...
- Android checkCallingPermission()方法返回值问题
Android开发检查权限时,发现调用checkCallingPermission()总是返回值-1,而Binder.getCallingPid() == Process.myPid()又总是返回tr ...
- [android] setOnTouchEvent 设置返回值为true 和 false的区别
今天在做自定义的可选文本的 TextView 类时,用到了 View 类的 setOnTouchListener(OnTouchListener l)事件监听,在构造 OnTouchListener ...
- phonegap android插件,启动activity并返回值
Your execute menthod is not quite right. When you do: return new PluginResult(PluginResult.Status.OK ...
- 【Python web自动化】之读取配置文件参数,利用cookie返回值进行跳过验证码进行登录操作
当进行Python的Web自动化时,会涉及到验证码问题,该如何跳过执行呢,下面请看代码: 1.首先新建配置文件*.ini格式 config.ini [db] #基础地址: baseurl = http ...
随机推荐
- HTML5的新标签之一的Canvas
一. <canvas>简介(了解) 1. 什么是canvas: 是HTML5提供的一种新标签 <canvas></canvas> 英 ['kænvəs] 美 [ ...
- VMwear安装Centos7超详细过程
本篇文章主要介绍了VMware安装Centos7超详细过程(图文),具有一定的参考价值,感兴趣的小伙伴们可以参考一下 1.软硬件准备 软件:推荐使用VMwear,我用的是VMwear 12 镜像:Ce ...
- 修改redis 持久化路径和日志 路径 ,修改kafka日志路径
redis修改持久化路径和日志路径 vim redis.conf logfile /data/redis_cache/logs/redis.log #日志路径 dir /data/redis_cach ...
- Linux系统下面crontab选择默认编译器
crontab修改默认编辑器 crontab默认编辑器为nano. 修改crontab默认编辑器为vi或者其他的编辑器. 法一: export EDITOR="/usr/bin/vim&qu ...
- python-ceilometerclient命令行(1)
1.导入模块,可以动态获取模块中方法并调用,其功能与from...import...一致 2. callback = getattr(actions_module, attr) 从模块中获取方法. 调 ...
- python学习day5 常量 运算符补充 流程控制基础
1.常量 值不会改变的量 python中没有特别的语法定义常量,一般约定用全大写字母命名常量,比如圆周率pi 2.预算符补充 2.1算数运算符 print(10/3)除法运算 print(10//3) ...
- Charles界面介绍及使用方法
本随笔主要内容: 一.Charles界面介绍 二.Charles使用 1.会话(Repeat.Focus.Compare.黑白名单等) 2.模拟请求做mock,使用断点.Map或Rewrite 3.指 ...
- ucore-lab1-练习2report
练习二实验报告 1.从CPU加电后执行的第一条指令开始,单步跟踪BIOS: 1.1默认的gdb需要进行一些额外的配置才能进行qemu的调试任务,qemu和gdb之间使用网络端口1234进行通信. la ...
- 第十章 优先级队列 (b3)完全二叉堆:删除与下滤
- Codeforces Beta Round #70 (Div. 2)
Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...