路过一个包上startActivity()?包上、startActivity

由网友(冷夜残月)分享简介:什么是通过捆绑到被从当前推出该活动的正确方法是什么?共享的属性?What's the correct way to pass a bundle to the activity that is being launched from the current one? Shared properties?推荐答案您有...

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

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

推荐答案

您有几种选择:

1)使用包从的意图:

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)使用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.

阅读全文

相关推荐

最新文章