我在网上看了很多 android 教程。在这些教程中,他们到处都使用 this
上下文作为上下文。我知道 this
关键字在 Java 中的含义,但我无法将 this 与 Android 编程中的 this
关键字相提并论。例如,在 developer.android.com 站点的 AlertDialog.Builder
中,只有一个参数引用了 Context,但我无法了解这个 this
表示此处。
最佳答案
如果你有一个 Activity 你可以使用 this
因为:
this
是类的当前实例- Activity 继承自“Context”类
这样您就可以将当前 Activity 用作上下文。
看here对于 Activity 文档
和here this
关于java - "this"上下文是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6520934/