简单的例子意图和捆绑 [英] Simple example for Intent and Bundle

查看:157
本文介绍了简单的例子意图和捆绑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新到Android几乎没有关于Java和XML的知识。 我通过PDF文件是我得到的净学习它。 我已经了解了吐司,一些关于意图,但我无法理解有关捆绑任何东西。我已经明白,它们被用来从一个活动数据传递到另一个,但我不能够实现这一点。

I'm new to android with almost no knowledge about Java and XML. I'm learning it through pdfs that i'm getting on net. I have learnt about Toast, a bit about Intents but me not able to understand anything about Bundles. I have understood that they are used to pass data from one activity to another but I'm not able to implement this.

请举一个简单的例子来实现相同的。

please give a simple example to implement the same.

作为例子,我刚刚创建了两个活动,即Main_Activity和Other_Activity,而我没有做任何事情来他们没有。

as for example I have just created two activities namely , Main_Activity and Other_Activity, and i haven't done anything to them yet.

请举个最简单的例子,这样我可以学习来实现。

Please give the simplest example so that i can learn to implement.

在此先感谢!

推荐答案

例如:

在MainActivity:

In MainActivity :

Intent intent = new Intent();
intent.setClass(this, Other_Activity.class);
intent.putExtra("EXTRA_ID", "SOME DATAS");
startActivity(intent);

在Other_Activity:

In Other_Activity :

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  Bundle extras = getIntent().getExtras();
  if (extras != null) {
   String datas= extras.getString("EXTRA_ID");
   if (datas!= null) {
        // do stuff
   }        
}

更多信息点击这里: <一href="http://developer.android.com/reference/android/content/Intent.html">http://developer.android.com/reference/android/content/Intent.html

More informations here : http://developer.android.com/reference/android/content/Intent.html

这篇关于简单的例子意图和捆绑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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