从一个意图传递一个长整型值到另一个 [英] passing a long value from one intent to another

查看:139
本文介绍了从一个意图传递一个长整型值到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从一个阶级的意图传递到另一个长期价值。但不知何故,我不似乎得到的语法或方法这样做。这样就解决了90%,我的问题。从MainActivity.java一个方法调用intentfunction(SETID)将其传递给在SelectOptions.java收到的意图。

I am trying to pass a long value from intent of one class to another. But Somehow I dont seem to get the syntax or method to do so. This would solve 90% of my problem. Passing it from a method called intentfunction(setid) in the MainActivity.java to a received intent in SelectOptions.java.

/ - MainActivity.java --- /

/--MainActivity.java---/

private void intentfunction(long setid)
{
     Intent intent = new Intent(this, SelectOptions.class);
     //editText = (EditText) findViewById(R.id.editText1);
     //editText = new EditText(this);
     etGWid.setText("");   //set the edit text to blank
    //String message = "TestHello";

    intent.putExtra(EXTRA_MESSAGE, setid);
    startActivity(intent);

}

像上面我希望实现。在这里,去Selectoptions.java的接收部分

SOmething like the above i wish to implement. And here goes the received part of Selectoptions.java

final Intent intent = getIntent();
    //String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
    long getid = intent.getLongExtra(MainActivity.EXTRA_MESSAGE, defaultValue)

这样的事情。

推荐答案

您已经正确地传递你的意图,现在在接收活动,让你可以使用捆绑的意图,

You have passed your intents correctly, now in the receiving activity to get the intent you could use bundles,

Bundle extras = getIntent().getExtras(); 
if (extras != null) {
    long getid = extras.getString('KEY',default_value);
}

这篇关于从一个意图传递一个长整型值到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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