passing a long value from one intent to another

若如初见. 提交于 2020-01-16 10:00:08

问题


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---/

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);

}

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)

Something like this.


回答1:


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);
}


来源:https://stackoverflow.com/questions/13671926/passing-a-long-value-from-one-intent-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!