问题
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