I'm having a weird problem when I try to send strings with intents when switching activities.
Here is what I do in class 1:
Intent myIntent = new Intent(SearchText.this, Search.class);
myIntent.putExtra("searchx", spinnerselected);
myIntent.putExtra("SearchText", input);
startActivity(myIntent);
Class 2:
Intent myIntent = getIntent();
searchText=myIntent.getStringExtra("SearchText");
spinnerselectednumber=Integer.parseInt(myIntent.getStringExtra("searchx"));
And using the debugger in the second class, its clear that there is a value in searchx.
Though the line myIntent.getStringExtra("searchx")
returns null
.
Why is this?
Try to add .ToString()
to myIntent.putExtra("searchx", spinnerselected);
so that it is myIntent.putExtra("searchx", spinnerselected.ToString());
This always works for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With