zoukankan      html  css  js  c++  java
  • Android Studio 使用Intent实现页面的跳转(带参数)

    不管是在APP,还是在网站中,页面之间的跳转都是很常见的,本文主要讲一下在APP中,如何通过Intent实现页面的跳转。

    不带参数:

    写在MainActivity页面的代码:

    1 Intent intent = new Intent();
    2 intent.setClass(MainActivity.this, LoginActivity.class);//从MainActivity页面跳转至LoginActivity页面
    3 this.startActivity(intent);

    带参数:

    写在SpendingActivity页面的代码:

    1 Intent intent=new Intent(SpendingActivity.this,ExpenseProcesActivity.class);//从SpendingActivity页面跳转至ExpenseProcesActivity页面
    2 intent.putExtra("strType", 0);//参数:name、value
    3 SpendingActivity.this.startActivity(intent);

    写在ExpenseProcesActivity接收页面的代码:

    1 private int type = 0;
    2 
    3 //接收传递过来的参数
    4 final Intent intent = getIntent();
    5 type = intent.getIntExtra("strType", 0);

    备注:

    可传递的参数有多种类型,在接收参数的时候,也要根据传入类型,选用对应的接收函数

    传递参数的类型,Eg:

    对应的接收函数,Eg:

  • 相关阅读:
    List<Map>遍历相加
    jqgrid属性
    idea Could not autowire. No beans of 'xxxx' type found
    【笔记】抓取百度贴吧
    python url中文转码
    python lxml 库
    Python 基础 (笔记)
    HTML 背景
    HTML Iframe
    HTML 响应式 Web 设计
  • 原文地址:https://www.cnblogs.com/AnneHan/p/9705431.html
Copyright © 2011-2022 走看看