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. ...
随机推荐
- MySql基础架构以及SQL语句执行流程
01. mysql基础架构 SQL语句是如何执行的 学习一下mysql的基础架构,从一条sql语句是如何执行的来学习. 一般我们写一条查询语句类似下面这样: select user,password ...
- Python 03 整型、字符串
1. 整型和布尔值 1.1 整型——数字(int) 用于比较和运算. 整型32位:-2**31 ~ -2**31-1 整型64位:-2**63 ~ -2**63-1 python2 :整型 int ...
- UGUI的图集处理方式-SpriteAtlas的前世今生
最糟糕的是人们在生活中经常受到错误志向的阻碍而不自知,真到摆脱了那些阻碍时才能明白过来. —— 歌德 说到UGUI的图集初学者可能觉得没什么难度,包括我刚开始接触的时候也是,甚至你在开发的时候只需要把 ...
- API 资源隔离系统设计与实现
(马蜂窝技术原创内容,公众号 ID:mfwtech) Part 1 背景 大交通业务需要对接机票.火车票.租车.接送机等业务的外部供应链,供应商的数据接口大部分通过 HTTP.HTTPS 等协议进行通 ...
- HTML(二)属性,标题,段落,文本格式化
HTML属性 HTML属性 HTML 元素可以设置属性 属性可以在元素中添加附加信息 属性一般描述于开始标签 属性总是以名称/值对的形式出现,比如:name="value" 常用属 ...
- CodeForces 834D The Bakery
The Bakery 题意:将N个数分成K块, 每块的价值为不同数字的个数, 现在求总价值最大. 题解:dp[i][j] 表示 长度为j 且分成 i 块的价值总和. 那么 dp[i][j] = max ...
- Linux系统调用表(x86_64)
内核版本 Linux 4.7 Note:64位系统中,不再使用int 0x80来进行系统调用,取而代之的是syscall指令 %rax System call %rdi %rsi %rdx %r10 ...
- python 中的while循环、格式化、编码初始
while循环 循环:不断重复着某件事就是循环 while 关键字 死循环:while True: 循环体 while True: # 死循环# print("坚强")# pr ...
- input上传按钮的优化
在使用input标签按钮的时候,<input type="file" value="" /> 显示很难看,怎么办? 使用label <li c ...
- docker-将自己的Linux打包为镜像
基于原始文件和目录从0开始制作镜像: 1).基于CentOS7 Linux纯净系统(初始化安装完成),将Linux整个系统打包成tar文件即可: cd /root/ tar --numeric-own ...