Activity的跳转与传值
Activity跳转,无返回结果
- ((Button) findViewById(R.id.Notepadv1)).setOnClickListener( new OnClickListener() {
- public void onClick(View v) {
- startActivity(new Intent (MyAndroidAppActivity.this, Notepadv1.class) );
- }
- });
Activity跳转,返回数据/结果
- static final int SEND_SMS_REQUEST = 0;
- static final int CALL_REQUEST = 1;
- ((Button) findViewById(R.id.sms)).setOnClickListener( new OnClickListener() {
- public void onClick(View v) {
- Intent intent = new Intent(MyAndroidAppActivity.this, SendSMSActivity.class);
- startActivityForResult(intent, SEND_SMS_REQUEST);
- }
- });
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == SEND_SMS_REQUEST) {
- if (resultCode == RESULT_OK) {
- Toast.makeText(this, "Send SMS RESULT_OK", Toast.LENGTH_SHORT).show();
- }else if (resultCode == RESULT_CANCELED) {
- Bundle bundle = data.getExtras();
- String phoneno = bundle.getString("phoneNO");
- Toast.makeText(this, "Send SMS RESULT_CANCELED "+phoneno, Toast.LENGTH_SHORT).show();
- }
- }else if (requestCode == CALL_REQUEST) {
- if (resultCode == RESULT_CANCELED) {
- Toast.makeText(this, "Call RESULT_CANCELED", Toast.LENGTH_SHORT).show();
- }
- }
- }
- ((Button) findViewById(R.id.send)).setOnClickListener( new Button.OnClickListener() {
- public void onClick(View v) {
- SendSMSActivity.this.setResult(RESULT_OK);
- SendSMSActivity.this.finish();
- }
- }):
- ((Button) findViewById(R.id.cancel)).setOnClickListener( new Button.OnClickListener() {
- public void onClick(View v) {
- // 实例化 Bundle,设置需要传递的参数
- Bundle bundle = new Bundle();
- bundle.putString("phoneNO", "020-123");
- SendSMSActivity.this.setResult(RESULT_CANCELED, SendSMSActivity.this.getIntent().putExtras(bundle));
- SendSMSActivity.this.finish();
- }
- });
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- // 是否触发按键为back键
- if (keyCode == KeyEvent.KEYCODE_BACK) {
- // 实例化 Bundle,设置需要传递的参数
- Bundle bundle = new Bundle();
- bundle.putString("phoneNO", "020-123");
- setResult(RESULT_CANCELED, this.getIntent().putExtras(bundle));
- this.finish();
- return true;
- }else {
- return super.onKeyDown(keyCode, event);
- }
- }
Activity传送数据
- // 在某个按钮响应事件里
- Intent intent = new Intent(this, TextInputActivity.class);
- intent.putExtra("Text", mText);
- intent.putExtra("TextColor", mTextColor);
- intent.putExtra("TextSize", mTextSize);
- intent.putExtra("TextBold", mTextBold);
- startActivityForResult(intent, REQUEST_TEXT);
- // in onCreate(Bundle savedInstanceState)
- Bundle extras = getIntent().getExtras();
- mText = extras.getString("Text");
- mTextColor = extras.getInt("TextColor");
- mTextSize = extras.getFloat("TextSize");
- mTextBold = extras.getBoolean("TextBold");
本文出自 “学习Android” 博客,请务必保留此出处http://android.blog.51cto.com/268543/323982
Activity的跳转与传值的更多相关文章
- 5.10学习总结——Activity的跳转和传值
使用sharedpreference是对信息的存储,也可以进行传值,今天通过查找资料,学习了Activity的跳转和传值方法. 跳转 1.显示跳转 4种方法 1 2 3 4 5 6 7 8 9 10 ...
- Android课程---Activity的跳转与传值(转自网上)
Activity跳转与传值,主要是通过Intent类来连接多个Activity,以及传递数据. Intent是Android一个很重要的类.Intent直译是“意图”,什么是意图呢?比如你想从这个 ...
- Activity的跳转与传值(转载)
Activity跳转与传值,主要是通过Intent类来连接多个Activity,以及传递数据. Intent是Android一个很重要的类.Intent直译是“意图”,什么是意图呢?比如你想从这个 ...
- Android开发10——Activity的跳转与传值
Activity跳转与传值,主要是通过Intent类,Intent的作用是激活组件和附带数据. 一.Activity跳转 方法一Intent intent = new Intent(A.this, B ...
- xamarin.android Activity之间跳转与传值
前言 由于需要,所以接触到这个新的安卓开发模式,我会把我的学习经历全都记录下来,希望对大家有用. 导读 关于Activity,学习过安卓的人也应该明白什么是Activity,推荐新手去看YZF的这篇文 ...
- Android开发之Activity的创建跳转及传值
在Android系统的江湖中有四大组件:活动(Activity), 服务(Service), 广播接收器(Broadcast Reciver)和内容提供者(Content Provider).今天所介 ...
- Android中实现activity的页面跳转并传值
一个Android应用程序很少会只有一个Activity对象,如何在多个Activity之间进行跳转,而且能够互相传值是一个很基本的要求. 本次我们就讲一下,Android中页面跳转以及传值的几种方式 ...
- Android学习之Activity跳转与传值
Activity跳转与传值,主要是通过Intent类,Intent的作用是激活组件和附带数据. 一.Activity跳转 方法一 Intent intent = new Intent(A.this, ...
- Intent实现页面跳转和传值
*Intent称为意图,是Android各大组件连接的桥梁 1.Activity页面跳转 同一个包内 Intent intent = new Intent(); intent.setClass(Mai ...
随机推荐
- Spring Boot(十六):使用 Jenkins 部署 Spring Boot
Jenkins 是 Devops 神器,本篇文章介绍如何安装和使用 Jenkins 部署 Spring Boot 项目 Jenkins 搭建.部署分为四个步骤: 第一步,Jenkins 安装 第二步, ...
- Maven 项目生成或者update jdk变为1.5的问题
在使用Maven构建项目时,生成的maven项目jdk默认使用的是jdk1.5. 在手动修改了jdk之后,update project之后jdk又会变为1.5. 或者用eclipse的Maven插件生 ...
- JS进阶系列之执行上下文
function test(){ console.log(a);//undefined; var a = 1; } test(); 也许你会遇到过上面这样的面试题,你只知道它考的是变量提升,但是具体的 ...
- oracle alter
ALTER TABLE (表名) ADD CONSTRAINT (索引名);ALTER TABLE (表名) DROP CONSTRAINT (索引名); ALTER TABLE (表名) ADD ( ...
- 小学四则运算APP 第一阶段冲刺
需求分析 1.相关系统分析员向用户初步了解需求,然后用word列出要开发的系统的大功能模块,每个大功能模块有哪些小功能模块,对于有些需求比较明确相关的界面时,在这一步里面可以初步定义好少量的界面.[1 ...
- Golang的panic和recover
panic 关键字panic的作用是制造一次宕机,宕机就代表程序运行终止,但是已经“生效”的延迟函数仍会执行(即已经压入栈的defer延迟函数,panic之前的). 为什么要制造宕机呢?是因为宕机不容 ...
- HDU 2032 杨辉三角
http://acm.hdu.edu.cn/showproblem.php?pid=2032 Problem Description 还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考 ...
- HTML5 Base64_encoding_and_decoding
https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding In JavaSc ...
- [转载]linux段页式内存管理技术
原始博客地址: http://blog.csdn.net/qq_26626709/article/details/52742470 一.概述 1.虚拟地址空间 内存是通过指针寻址的,因而CPU的字长决 ...
- Linux net core docker hello world 简单使用
安装.net core From 官网 sudo sh -c 'echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft ...