路过一个包上startActivity()? [英] Passing a Bundle on startActivity()?

查看:160
本文介绍了路过一个包上startActivity()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是通过捆绑到被从当前推出该活动的正确方法是什么?共享的属性?

What's the correct way to pass a bundle to the activity that is being launched from the current one? Shared properties?

推荐答案

您有几种选择:

1)使用包从的的://开发商.android.com /参考/安卓/内容/ Intent.html>意图

1) Use the Bundle from the Intent:

Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(key, value);  

2)创建一个新的捆绑

2) Create a new Bundle

Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.putString(key, value);
mIntent.putExtras(mBundle);

3)使用<一个href="http://developer.android.com/reference/android/content/Intent.html#putExtra%28java.lang.String,%20java.lang.String%5b%5d%29">putExtra()该意向书的快捷方式

3) Use the putExtra() shortcut method of the Intent

Intent mIntent = new Intent(this, Example.class);
mIntent.putExtra(key, value);


然后,在启动的活动,您将通过阅读:


Then, in the launched Activity, you would read them via:

String value = getIntent().getExtras().getString(key)

注:捆绑有得与放的方法对所有的基本类型,parcelables的,和Serializables。我只是用字符串示范的目的。

NOTE: Bundles have "get" and "put" methods for all the primitive types, Parcelables, and Serializables. I just used Strings for demonstrational purposes.

这篇关于路过一个包上startActivity()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆