Null pointer when getting intent extra
Some times when running my app I get a null pointer when retrieving a value bundled with an intent
setting it i开发者_如何转开发n one class
private void start(){
Intent i = new Intent(this,Tabs.class);
i.putExtra("helper", checked);
startActivity(i);
}
checked is a boolean value and is never null
getting it in the other class
private void getExtra(){
Bundle extras = getIntent().getExtras();
mExtra = extras.getBoolean("helper");
}
any ideas as to why it would be null sometimes?
Use getBooleanExtra()
to get the value from intent
Sample Code
boolean mExtra = getIntent().getBooleanExtra("helper", false);
精彩评论