开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜