java - "this"上下文是什么意思?

标签 java android

我在网上看了很多 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/

相关文章:

java - 提高 SQL 从 JDBC (SQL Server) 插入 XML 列的速度

android - 为什么要使用 Retrofit?

android - BitmapFactory.decodeFile 内存不足,图像 2400x2400

android - 播放ToneGenerator原因ANR

java - 字符串数组声明的差异。 String[] foo 或 String foo[]

java - 如何在JList中显示模型的值?

java - 可以推荐哪些 Java 原生编译器?

java - 将 Jython PythonInterpreter 中的参数添加到 "execfile"函数

Android - LoopJ AndroidAsyncHttp - 无 POST 参数

android - 如何从JsonObject获取数据并在Kotlin的RecyclerView上设置为Array?