Android Studio [页面的跳转和传值]
AActivity.java
package com.xdw.a122.jump; import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast; import com.xdw.a122.R; public class AActivity extends AppCompatActivity {
private Button mBtnJump;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a);
mBtnJump=findViewById(R.id.btn_jump1);
mBtnJump.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//显式1
Intent intent=new Intent(AActivity.this,BActivity.class);
Bundle bundle = new Bundle(); //为bundle分配
bundle.putString("name","Bollen"); //转入bundle
bundle.putInt("number",250); //转入bundle
intent.putExtras(bundle); //传输bundle--intent
// startActivity(intent); //执行
startActivityForResult(intent,0); //执行 并返回一个结果 请求码0
//显式2
// Intent intent=new Intent();
// intent.setClass(AActivity.this,BActivity.class);
// startActivity(intent);
//显式3
// Intent intent=new Intent();
// intent.setClassName(AActivity.this,"com.xdw.a122.jump.BActivity");
// startActivity(intent);
//显式4
// Intent intent=new Intent();
// intent.setComponent(new ComponentName(AActivity.this,BActivity.class));
// startActivity(intent);
}
});
} @Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Toast.makeText(AActivity.this,data.getExtras().getString("title"),Toast.LENGTH_LONG).show();
}
}
BActivity.java
package com.xdw.a122.jump; import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView; import com.xdw.a122.R; public class BActivity extends AppCompatActivity {
private TextView mTvTitle;
private Button mBtnFinish;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);
mTvTitle=findViewById(R.id.tv_title);
mBtnFinish=findViewById(R.id.btn_finish);
final Bundle bundle=getIntent().getExtras(); //接收Extras
String name=bundle.getString("name");
int number=bundle.getInt("number");
mTvTitle.setText(name+","+number); //显示传递值
mBtnFinish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(); //为返回值bundler1分配空间
Bundle bundle1=new Bundle();
bundle1.putString("title","我回来了");
intent.putExtras(bundle1);
setResult(AActivity.RESULT_OK,intent); //返回ok-1
finish(); //关闭页面
}
});
}
}
activity_a.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:gravity="center_horizontal"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_jump1"
android:layout_width="100dp"
android:layout_height="50dp"
android:background="@drawable/bg_btn3"
android:text="Jump"/>
</LinearLayout>
activity_b.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"
android:orientation="vertical"
android:gravity="center_horizontal"> <TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="#000000"/>
<Button
android:id="@+id/btn_finish"
android:layout_width="100dp"
android:layout_height="50dp"
android:text="返回"
android:textSize="20sp"
android:background="@drawable/bg_btn3"/>
</LinearLayout>
Android Studio [页面的跳转和传值]的更多相关文章
- Android课程---Activity的跳转与传值(转自网上)
Activity跳转与传值,主要是通过Intent类来连接多个Activity,以及传递数据. Intent是Android一个很重要的类.Intent直译是“意图”,什么是意图呢?比如你想从这个 ...
- Android Studio 代码页跳界面 /java和XML快速切换技巧
https://www.cnblogs.com/simadi/p/6698666.html?utm_source=itdadao&utm_medium=referral 今天又发现了一个And ...
- Android学习之Activity跳转与传值
Activity跳转与传值,主要是通过Intent类,Intent的作用是激活组件和附带数据. 一.Activity跳转 方法一 Intent intent = new Intent(A.this, ...
- HTML页面之间跳转与传值(JS代码)
跳转的方法如下: 方法一: window.location.href = "b.html"; 方法二(返回上一个页面,这个应该不算,先放在这): window.history.ba ...
- JSP页面的跳转及传值
1.response.sendRedirect("跳转到页面的URL"); 该方法通过修改HTTP协议的HEADER部分,对浏览器下达重定向指令的,使浏览器显示重定向网页的内容. ...
- 第二章:Android Studio概述(二)[学习Android Studio汉化教程]
The Main Menu Bar 主菜单栏 主菜单栏位于Android Studio的最上面,你几乎可以利用主菜单和其子菜单来执行任何操作.不像Android Studio中其他的一些菜单,主菜单 ...
- Android零基础入门第10节:开发IDE大升级,终于迎来了Android Studio
原文:Android零基础入门第10节:开发IDE大升级,终于迎来了Android Studio 通过前面几期的学习,我们知道了Android的前世今生,也了解了Android的系统架构和应用组件,也 ...
- Android tab_Host页面跳转,传值,刷新等问题汇总
之前做了一个项目是关于Tab_Host的,现在完成了恰逢闲余写份总结,主要涉及里面遇到问题以及解决方案的. (首先说明这份代码是在eoe 下载的,这里感谢分享的那位朋友,限于我的工程是公司的不能拿出来 ...
- Android Studio计时跳转或点击跳转至主页面
这个总体来说是比较简单的,计时跳转一般调用Android Studio中的Handler方法. 一.发生点击事件跳转页面 mBtnTextView = (Button) findViewById(R. ...
随机推荐
- d3.js V5版本在vue里使用 自定义节点图片
var width = this.$refs.topInfo.offsetWidth; var height = this.$refs.topInfo.offsetHeight; var img_w ...
- 【入门】广电行业DNS、DHCP解决方案详解(一)——历史及现状篇
广电发展历史 单项网络 双向网络 智能网络 广电网络现状 广电网络典型特征 接入技术混杂 承载业务多样化 业务终端错综复杂 其他 网络现状模型 总结 广电发展历史 广电就是广播电视,广电发展可以分为三 ...
- 设计模式(C#)——05适配器模式
推荐阅读: 我的CSDN 我的博客园 QQ群:704621321 自然界有一条规则--适者生存.意思是生物要使用自然界的变化:在程序界中则需要新环境调用现存对象.那么,如何在新环境中 ...
- Spring框架入门之Spring4.0新特性——泛型注入
Spring框架入门之Spring4.0新特性——泛型注入 一.为了更加快捷的开发,为了更少的配置,特别是针对 Web 环境的开发,从 Spring 4.0 之后,Spring 引入了 泛型依赖注入. ...
- Attention机制的精要总结,附:中英文机器翻译的实现!
1. 什么是Attention机制 在"编码器-解码器(seq2seq)"⼀节⾥,解码器在各个时间步依赖相同的背景变量来获取输⼊序列信息.当编码器为循环神经⽹络时,背景变量来⾃它最 ...
- (数据科学学习手札68)pandas中的categorical类型及应用
一.简介 categorical是pandas中对应分类变量的一种数据类型,与R中的因子型变量比较相似,例如性别.血型等等用于表征类别的变量都可以用其来表示,本文就将针对categorical的相关内 ...
- 从Linux服务器下载上传文件
首先要确定好哪两种的连接:Linux常用的有centors和unbantu两种版本,PC端Mac和Windows 如果在两个Linux之间传输,或Linux和Mac之间传输可以使用scp命令,类似于s ...
- Vim高手,从来不用鼠标2——替换、撤销、缩进、查找
本文章原创首发于公众号:编程三分钟 vim 替换.撤销.缩进.查找 上一次我们掌握了移动.跳转.定位.操作(删除.复制.粘贴),基本使用vim脱离鼠标完全是可以做到的了.速记如下: 移动: h,l,j ...
- Codeforces Round #486 (Div. 3)988E. Divisibility by 25技巧暴力||更暴力的分类
传送门 题意:给定一个数,可以对其做交换相邻两个数字的操作.问最少要操作几步,使得可以被25整除. 思路:问题可以转化为,要做几次交换,使得末尾两个数为00或25,50,75: 自己一开始就是先for ...
- There is No Alternative CSU - 2097 最小生成树
Description ICPC (Isles of Coral Park City) consist of several beautiful islands. The citizens reque ...