Android 我可以从OnCreate方法之外访问Intent.extras吗?
我正在使用Model View Presenter设计模式构建一个Android应用程序。我的应用程序收到Firebase消息通知,当我的应用程序未运行时,该通知会使用意图将数据传递到应用程序(从通知栏)。我已经完成了所有这些工作,并且可以在onCreate方法中通过以下代码查看意图数据:Android 我可以从OnCreate方法之外访问Intent.extras吗?,android,android-intent,mvp,Android,Android Intent,Mvp,我正在使用Model View Presenter设计模式构建一个Android应用程序。我的应用程序收到Firebase消息通知,当我的应用程序未运行时,该通知会使用意图将数据传递到应用程序(从通知栏)。我已经完成了所有这些工作,并且可以在onCreate方法中通过以下代码查看意图数据: intent.extras?.let { for (key in it.keySet()) { val value = intent.extras?.get(k
intent.extras?.let {
for (key in it.keySet()) {
val value = intent.extras?.get(key)
Log.d(TAG, "Key: $key Value: $value")
}
}
我想将此信息保存到我的演示者,但演示者尚未创建。我可以在onCreate之后访问intents.extras吗?我尝试了并得到了一个空指针异常,因此似乎在onCreate之后意图对象被销毁了。是这样吗?我的演示者如何访问此数据?此时,我唯一的想法是在活动中创建一个成员变量,然后将该数据保存到onCreate中的该成员变量中,然后让演示者获取该变量,但我有点反对使用哑视图的模型视图演示者设计模式
我可以在onCreate之后访问intents.extras吗
对
我尝试了并得到了一个空指针异常,因此似乎在onCreate之后意图对象被销毁了。是这样吗
没有
但是,Kotlin的一个风险是,如果您有一个名为intent
-intent的属性或变量。extras
可能引用该属性或变量,而不是对活动本身调用getIntent()