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 [页面的跳转和传值]的更多相关文章

  1. Android课程---Activity的跳转与传值(转自网上)

    Activity跳转与传值,主要是通过Intent类来连接多个Activity,以及传递数据.   Intent是Android一个很重要的类.Intent直译是“意图”,什么是意图呢?比如你想从这个 ...

  2. Android Studio 代码页跳界面 /java和XML快速切换技巧

    https://www.cnblogs.com/simadi/p/6698666.html?utm_source=itdadao&utm_medium=referral 今天又发现了一个And ...

  3. Android学习之Activity跳转与传值

    Activity跳转与传值,主要是通过Intent类,Intent的作用是激活组件和附带数据. 一.Activity跳转 方法一 Intent intent = new Intent(A.this, ...

  4. HTML页面之间跳转与传值(JS代码)

    跳转的方法如下: 方法一: window.location.href = "b.html"; 方法二(返回上一个页面,这个应该不算,先放在这): window.history.ba ...

  5. JSP页面的跳转及传值

    1.response.sendRedirect("跳转到页面的URL"); 该方法通过修改HTTP协议的HEADER部分,对浏览器下达重定向指令的,使浏览器显示重定向网页的内容. ...

  6. 第二章:Android Studio概述(二)[学习Android Studio汉化教程]

    The Main Menu Bar 主菜单栏  主菜单栏位于Android Studio的最上面,你几乎可以利用主菜单和其子菜单来执行任何操作.不像Android Studio中其他的一些菜单,主菜单 ...

  7. Android零基础入门第10节:开发IDE大升级,终于迎来了Android Studio

    原文:Android零基础入门第10节:开发IDE大升级,终于迎来了Android Studio 通过前面几期的学习,我们知道了Android的前世今生,也了解了Android的系统架构和应用组件,也 ...

  8. Android tab_Host页面跳转,传值,刷新等问题汇总

    之前做了一个项目是关于Tab_Host的,现在完成了恰逢闲余写份总结,主要涉及里面遇到问题以及解决方案的. (首先说明这份代码是在eoe 下载的,这里感谢分享的那位朋友,限于我的工程是公司的不能拿出来 ...

  9. Android Studio计时跳转或点击跳转至主页面

    这个总体来说是比较简单的,计时跳转一般调用Android Studio中的Handler方法. 一.发生点击事件跳转页面 mBtnTextView = (Button) findViewById(R. ...

随机推荐

  1. spss数据分析可以被人工智能替换吗

    作为一名需要对课题进行研究的大学生,我在日常学习中经常需要用到spss,虽然老师上课已经初步教了我如何用这个软件,然而,在使用过程中我还是遇到了许多问题.具体来说,就是这个软件在很多地方都不够与时俱进 ...

  2. ubuntu中rc.local不执行问题

    解决思路概括起来如下: 1.首先排除脚本自身问题,可以手动点杠执行下试试, 2.脚本确定没问题后,放到开机启动程序引用的路径下,办法如下 2.1.查看系统的运行级别 2.2.到对应运行的rcX.d的目 ...

  3. SCRUM的五个事件

    转自:http://www.scrumcn.com/agile/scrum-knowledge-library/scrum.html#tab-id-7 Scrum 使用固定的事件来产生规律性,以此来减 ...

  4. Java微服务(一):dubbo-admin控制台的使用

    1.环境准备 使用CentOS7+Docker+Zookeeper3.4.10搭建dubbo微服务 1.1.安装docker容器 (1).uname -r:docker要求CentOS的内核版本高于3 ...

  5. ui、li模拟下拉框

    转载:原文地址:https://www.jianshu.com/p/e303e0298e9e 效果图: HTML: <div class="rank_top"> < ...

  6. MyCat数据库的基础配置及使用

    一.为什么需要分布式数据据库 随着计算机和信息技术的迅猛发展,行业应用系统的规模迅速扩大,行业应用所产生的数据量呈爆炸式增长,动辄达到数百TB甚至数百PB的规模,已远远超出传统计算技术和信息系统的处理 ...

  7. 【LeetCode】435-无重叠区间

    题目描述 给定一个区间的集合,找到需要移除区间的最小数量,使剩余区间互不重叠. 注意: 可以认为区间的终点总是大于它的起点. 区间 [1,2] 和 [2,3] 的边界相互"接触", ...

  8. 你真的了解Grid布局吗?

    Grid网格布局 概述:Grid将容器划分为一个个网格,通过任意组合不同的网格,做出你想想要的布局 Grid与flex布局相似,将整个Grid分为了容器与子项(格子) Grid容器的三个重要的概念: ...

  9. React Hooks 你不来了解下?

    前言 最近在看 React 的新语法-- React Hooks,只能一句话概括:React 语法真的是越来越强大,越写代码越少. 强烈推荐还没看 React Hooks 的同学去学习下,这会让你写r ...

  10. Docker下Jedis体验

    jedis是redis的java版本的客户端实现,本文通过一些web请求&响应的实例展示了jedis的基本用法: 开始编码前我们先把环境准备好,总共两个server,对应两个docker容器: ...