我创建了一个MyApplication扩展类Application并在清单中定义了它。
在MyApplication's方法中,使用或获取应用程序上下文onCreate()有什么区别吗?thisgetApplicationContext()
(据推测,后者只是因为Application是 a而存在Context,但我只需要确定。)
我创建了一个MyApplication扩展类Application并在清单中定义了它。
在MyApplication's方法中,使用或获取应用程序上下文onCreate()有什么区别吗?thisgetApplicationContext()
(据推测,后者只是因为Application是 a而存在Context,但我只需要确定。)
您的类MyApplication间接继承自Context该类(Applicaiton > ContextWrapper > Context)。因此,当您将引用this用作 Context 实例时,您只是在使用多态性概念。
使用 this 或 getApplicationContext() 来获取应用程序上下文有什么区别吗?
没有区别。