Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java getIntent()始终返回null_Java_Android - Fatal编程技术网

Java getIntent()始终返回null

Java getIntent()始终返回null,java,android,Java,Android,此代码启动活动: Intent intent = new Intent(context, GameActivity.class); intent.putExtra("load", true); startActivity(intent); private Intent intent = this.getIntent(); 这就是我如何尝试在新活动中获得目的: Intent intent = new Intent(context, GameActivity.class);

此代码启动活动:

Intent intent = new Intent(context, GameActivity.class);
    intent.putExtra("load", true);
    startActivity(intent);
private Intent intent = this.getIntent();
这就是我如何尝试在新活动中获得目的:

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();
onCreate
内部调用
getIntent()
,或在生命周期的另一个回调中调用

按如下方式进行尝试:

private boolean value =getIntent().getBoolean("load");

在错误使用之前,请阅读的功能。谢谢。我将这一行移到onCreate()中,它工作得很好。