• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > Android--Activity在跳转时携带数据

Android--Activity在跳转时携带数据

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了打开网页时自动跳转,网页打开时不跳转,打开网页时不自动跳转,访问时被跳转到指定ip,cdr破解时跳转网页等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Android--Activity在跳转时携带数据


首先看看两种传递方法示例:(一个简单姻缘计算器)

主Activity

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    public void click(View v){
    	Intent intent = new Intent(this, SecondActivity.class);
    	//把数据封装至intent对象中
//    	intent.putExtra("malename", "张三");
//    	intent.putExtra("femalename", "芙蓉姐姐");
    	
    	//把数据封装至bundle对象中
    	Bundle bundle = new Bundle();
    	bundle.putString("malename", "张三");
    	bundle.putString("femalename", "芙蓉姐姐");
    	
    	//把bundle对象封装至intent对象中
    	intent.putExtras(bundle);
    	startActivity(intent);
    }
    
}
import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class SecondActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_second);
		
		Intent intent = getIntent();
		//从intent对象中把封装好的数据取出来
//		String maleName = intent.getStringExtra("malename");
//		String feMaleName = intent.getStringExtra("femalename");
		
		Bundle bundle = intent.getExtras();
		String maleName = bundle.getString("malename");
		String feMaleName = bundle.getString("femalename");
		
		Random rd = new Random();
		int yinyuan = rd.nextInt(100);
		
		TextView tv = (TextView) findViewById(R.id.tv);
		tv.setText(maleName + "和" + feMaleName + "的姻缘值为" + yinyuan);
	}
}

activity_main.xml:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".MainActivity" android:orientation="vertical">

    <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这是姻缘计算器,很准的哟">

    <edittext android:id="@+id/et_malename" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="张三">
    <edittext android:id="@+id/et_femalename" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="芙蓉姐姐"><button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="计算" android:onclick="click"></button></edittext></edittext></textview></linearlayout>
activity_second.xml:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <textview android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这是第二个Activity">

</textview></relativelayout>

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Android--Activity在跳转时携带数据

相关文章

  • 2017-05-26Android 之 图片压缩
  • 2017-05-26Android应用开发必备的20条技能
  • 2017-05-26NDK-JNI实战教程(二) JNI官方中文资料,ndk-jnijni
  • 2017-05-26我的android学习经历8,android学习经历8
  • 2017-05-26android:从另外一个activity中返回数据
  • 2017-05-26记一次Android系统下解决音频UnderRun问题的过程
  • 2017-05-26Android新手入门2016(8)--ListView之ArrayAdapter
  • 2017-05-26LoaderManager与CursorLoader用法,cursorloader
  • 2017-05-221.0 Android基础入门教程
  • 2017-05-26【转载】ReactiveX 的理念和特点,转载reactivex理念

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • Android--Handler的使用方法:在子线程中更新界面
    • 安卓开源项目周报0222,安卓开源项目0222
    • AsyncTask源码探究,asynctask源码
    • redis使用内存调整及优化
    • 安卓开发 第一篇 关于依赖注入框架dagger2的使用和理解
    • Android音频开发之基础知识介绍
    • android 5.X Toolbar+DrawerLayout实现抽屉菜单
    • 总结一下Android中主题(Theme)的正确玩法,androidtheme
    • Android最佳实践之SystemBar状态栏全版本适配方案
    • 美女的秘密应用项目源码,秘密项目源码

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有