iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android Activity中使用Intent实现页面跳转与参数传递的方法
  • 466
分享到

Android Activity中使用Intent实现页面跳转与参数传递的方法

页面跳转方法参数intentactivityAndroid 2022-06-06 08:06:17 466人浏览 泡泡鱼
摘要

本文实例讲述了Android Activity中使用Intent实现页面跳转与参数传递的方法。分享给大家供大家参考,具体如下: 新建一个FirstAvtivity.java

本文实例讲述了Android Activity中使用Intent实现页面跳转与参数传递的方法。分享给大家供大家参考,具体如下:

新建一个FirstAvtivity.java


package com.zhuguangwei;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class FirstActivity extends Activity {
  private Button myButton;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    myButton = (Button) findViewById(R.id.myButton);
    myButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent intent = new Intent();
        //Intent传递参数
        intent.putExtra("testIntent", "123");
        intent.setClass(FirstActivity.this, SecondActivity.class);
        FirstActivity.this.startActivity(intent);
      }
    });
  }
}

新建第二个SecondActivity.java


package com.zhuguangwei;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class SecondActivity extends Activity{
  private TextView myTextView;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.other);
    //使用Intent对象得到FirstActivity传递来的参数
    Intent intent = getIntent();
    String value = intent.getStringExtra("testIntent");
    myTextView = (TextView) findViewById(R.id.myTextView);
    myTextView.setText(value);
  }
}

两个Activity都要在AndroidMenifest.xml中注册

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android编程之activity操作技巧总结》、《Android视图View技巧总结》、《Android操作sqlite数据库技巧总结》、《Android操作JSON格式数据技巧总结》、《Android数据库操作技巧总结》、《Android文件操作技巧汇总》、《Android编程开发之SD卡操作方法汇总》、《Android开发入门与进阶教程》、《Android资源操作技巧汇总》及《Android控件用法总结》

希望本文所述对大家Android程序设计有所帮助。

您可能感兴趣的文章:Android使用Intent隐式实现页面跳转Android Intent实现页面跳转的两种方法Android Intent实现页面跳转的方法示例Android使用Intent实现页面跳转Android 实现页面跳转Android使用Circular Reveal动画让页面跳转更炫酷Android编程中Intent实现页面跳转功能详解Android使用Intent显示实现页面跳转


--结束END--

本文标题: Android Activity中使用Intent实现页面跳转与参数传递的方法

本文链接: https://www.lsjlt.com/news/24687.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作