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. 快应用list组件 scrollTo 方法的调用方式

    例如,滚动到list 的第4个list-item: this.$element('alist').scrollTo({index:3})

  2. 拖动水滴给土地浇水(CocosCreator)

    推荐阅读:  我的CSDN  我的博客园  QQ群:704621321 一.前沿       最近在做农场的模块,需要实现拖动水滴图标(

  3. windows系统查询指定端口运行的进程并关闭

    假如占用的端口是80: 先打开cmd命令窗口 再查找80端口占用的进程:netstat  -aon|findstr  "80"    ,找到对应的程序的PID号: 根据PID号找到 ...

  4. 从无到有构建vue实战项目(八)

    十六.vue-lazyload的使用 首先,我们需要下载vue-lazyload包: npm i vue-lazyload -S 下载好之后,我们将它引入到自己的项目: //main.js //引入图 ...

  5. Python Web 之 Flask

    FLASK 一.概述 flask是一个基于python并依赖于Jinja2模板引擎和WerkZeug WSGI(Web Server Gatewey InterFace.web)服务的框架 WSGI: ...

  6. String类的intern()方法,随常量池发生的变化

    JVM的知识这里总结的很详细:https://github.com/doocs/jvm/blob/master/README.md,因此在本博客也不会再对其中的东西重复总结了. intern的作用 简 ...

  7. python控制窗口移动(画圆)

    import win32con import win32gui import time import math notepad = win32gui.FindWindow("Notepad& ...

  8. IT项目经理入门心法

  9. P2467 [SDOI2010]地精部落 DP

    传送门:https://www.luogu.org/problemnew/show/P2467 参考与学习:https://www.luogu.org/blog/user55639/solution- ...

  10. atcoder D - 11(组合数学)

    题目链接:http://arc077.contest.atcoder.jp/tasks/arc077_b 题解:有n+1个数只有一个数字是有重复出现的,要求一共有多少不同的组合显然和这两个数的位置有关 ...