发送类之间的变量通过意向 [英] Send a variable between classes through the Intent

查看:101
本文介绍了发送类之间的变量通过意向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到使用浏览屏幕的意图问题。我想给一个变量,并在其他类中使用它。

I'm getting problems using the Intent for navigate through the screens. I want to send a variable and use it in the other class.

我使用的方法,该方法采用可变的,但我不知道如何与意图的新屏幕,将用它来做一些事情把它。

I'm using a method, the method takes the variable but i don't know how to send it with the intent to the new screen, which will use it to do some things.

主类调用梅托德:

private void pantallaDetalles(final int identificador)
{
     startActivityForResult(new Intent(this,MostrarDetalles.class),REQST_CODE);
}

MostrarDetalles.class是*的.java将于变量。我开始时是这样的:

MostrarDetalles.class is the *.java which will take the variable. I'm begining it like this:

public class MostrarDetalles extends Activity {

    SQLiteDatabase db;

    public void onCreate(Bundle savedInstanceState)
        {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.detalles);


         //more code...


         Cursor c = db.rawQuery("SELECT * FROM table WHERE _id="+ identificador, null);

        }

你有没有看到?我说的这一点。我不知道如何从主类通过意向发送identificador变量第二类。

Did you see? I'm talking about this. I don't know how to send the "identificador" variable from the main class to the second class through the Intent.

您能帮我吗?感谢您的意见非常多。

Can you help me with this? Thank you very much in advice.

JMasia。

推荐答案

使用临时演员在捆绑的意图。

Use the extras bundle in the intent.

Intent i = new Intent(...);
i.putExtra("name_of_extra", myObject);

然后在的onCreate:

Then on onCreate:

getIntent.getIntExtra("name_of_extra", -1);

这篇关于发送类之间的变量通过意向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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