Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

myIntent.getStringExtra returns null? [duplicate]

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?

like image 540
Omar Avatar asked Mar 27 '11 17:03

Omar


1 Answers

Try to add .ToString() to myIntent.putExtra("searchx", spinnerselected); so that it is myIntent.putExtra("searchx", spinnerselected.ToString()); This always works for me

like image 138
Aiden Strydom Avatar answered Oct 03 '22 11:10

Aiden Strydom