Java 片段中的上下文和活动之间有什么区别?

Java 片段中的上下文和活动之间有什么区别?,java,android,kotlin,Java,Android,Kotlin,当我在一个片段中时,this.context和this.activity 例如: with context>intent只要应用程序存在就存在 with activity>intent只要活动存在就存在 现在您知道您需要什么了,大多数情况下-上下文是活动的超类。这是否回答了您的问题?这可能就是你想要的答案是的,这很好answer@Ho别忘了投票,兄弟…:-)是的,我会这样做。我不认为片段中的getContext会返回应用程序。请看这里: val intent = Intent(this.acti

当我在一个片段中时,
this.context
this.activity
例如:


with context>intent只要应用程序存在就存在

with activity>intent只要活动存在就存在


现在您知道您需要什么了,大多数情况下-上下文是活动的超类。

这是否回答了您的问题?这可能就是你想要的答案是的,这很好answer@Ho别忘了投票,兄弟…:-)是的,我会这样做。我不认为片段中的
getContext
会返回应用程序。请看这里:
val intent = Intent(this.activity!! , Activity::class.java)

val intent = Intent(this.context!! , Activity::class.java)