I’m trying to use putExtra and getExtras to pass some information in an android game I’m writing (it’s a score). When I’m passing it, I use this code in the one class to put in the information:
Intent winScreen = new Intent(context, WinScreen.class);
winScreen.putExtra("score", "123");
And when I’m getting it, I’m using:
Intent x=new Intent(this, GameCall.class);
Bundle ebundle = x.getExtras();
String score = (String) x.getExtras().getSerializable("score");
I’m just trying to test with a sample score right now, so I don’t think setting the value correctly is the problem. That was the suggestion I saw elsewhere for why such a null pointer would occur. I know it understands “score” as an extra. So I am stumped as to where the information is being lost!
When you use an
Intentto start a new Activity, you must usegetIntent()to get that specific instance of the intent. UsingIntent x=new Intent(this, GameCall.class);won’t work. Try the following code: