Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 in 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?

like image 577
tyczj Avatar asked Jul 31 '26 01:07

tyczj


1 Answers

Use getBooleanExtra() to get the value from intent

Sample Code

boolean mExtra = getIntent().getBooleanExtra("helper", false);

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!