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. ...
随机推荐
- HuffmanTree
/* 例如,对于数列{pi}={5, 3, 8, 2, 9},Huffman树的构造过程如下: 1. 找到{5, 3, 8, 2, 9}中最小的两个数,分别是2和3,从{pi}中删除它们并将和5加入, ...
- WPF注册热键后处理热键消息(非winform方式)
由于最近在做wpf版的截图软件,在处理全局热键的时候,发现国内博客使用的都是winform窗体的键盘处理方式,此方式需要使用winform的动态库,如此不协调的代码让我开始在github中寻找相关代码 ...
- Hexo+Github: 博客网站搭建完全教程(看这篇就够了)
本篇教程首次发布在个人博客:sunhwee.com,想要获得最佳阅读体验,欢迎前往,建议用电脑查看教程文档. # 阅读须知 注意,这篇文章篇幅较长,主要针对新手,每一步很详细,所以可能会显得比较啰嗦, ...
- 怎样才算精通Linux
1.掌握至少50个以上的常用命令(包括grep.awk.sed.ps.find等等吧,熟练使用,基础的选项不用man) 2.熟悉Gnome/KDE等X-windows桌面环境操作 3.掌握.tgz.. ...
- CentOS搭建php + nginx环境
更新Centos的yum源 yum update 安装EPEL源和REMI源 yum install epel-release yum install http://rpms.remirepo.net ...
- Oracle - View
Oracle View的创建 Create Or Replace View ViewName As Select * From Tables/View Where 条件;
- 洛谷 P1262 【间谍网络】
题库 : 洛谷 题号 : 1262 题目 : 间谍网络 link : https://www.luogu.org/problemnew/show/P1262 思路 : 这题可以用缩点的思想来做.先用T ...
- Redis主从复制的原理
更多内容,欢迎关注微信公众号:全菜工程师小辉.公众号回复关键词,领取免费学习资料. 在Redis集群中,让若干个Redis服务器去复制另一个Redis服务器,我们定义被复制的服务器为主服务器(mast ...
- python控制窗口缩放
import win32gui import win32con import time # 使用之前先打开一个记事本 notepad = win32gui.FindWindow("Notep ...
- Python和Sublime安装教程
Python安装 安装python可以去https://www.python.org官网下载 点开官网后点击下图我圈出来的地方 然后翻到页面最后,选择要安装的版本 点击下载后打开,将 Add Pyt ...