getIntent()始终返回null

西蒙

此代码启动活动:

Intent intent = new Intent(context, GameActivity.class);
    intent.putExtra("load", true);
    startActivity(intent);

这是我尝试获得新活动的意图的方法:

private Intent intent = this.getIntent();

有人告诉我尝试包括以下内容:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);
}

但这无济于事。在几次崩溃之后,我添加了:

if (intent == null) Log.w("Intent", "Intent is null");

我究竟做错了什么?

黑带
private Intent intent = this.getIntent();

通话getIntent()onCreate或在生命周期的另一个回调。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章