此运算符在 android 中的不同用法
Different use of this operator in android
我想知道这个运算符在 android 中的不同用法。我看过一些例子,但我很困惑:
Intent intent=new intent(Main Activity.this, Second Activity.class)
这里的"this"指的是什么?
Handler handler= new handler();
Thread t1;
t1=new thread(new runnable)){
void run(){
handler.postdelayed(this,2000);
}
}
这里的"this"指的是什么?
我知道 "this" 指的是 class 的当前实例,但这里的实例正在传递线程 class 或任何其他任何人都知道的关于此关键字的示例.请告诉我。
我是 android 的初学者。对我理清概念有很大帮助
您使用的 intent 函数以 Context 和 Class 作为参数,
Intent(Context packageContext, Class<?> cls)
因此这里的 this
是上下文。所以一般来说,如果您想使用当前的 class 作为上下文作为某些功能的参数,请使用 this
。
详细了解 Intent 构造函数 here
在第二个代码块中,this
指的是您希望函数 运行 打开的 Runnable class。
我建议你google关于函数或构造函数来回溯参数是什么。
我想知道这个运算符在 android 中的不同用法。我看过一些例子,但我很困惑:
Intent intent=new intent(Main Activity.this, Second Activity.class)
这里的"this"指的是什么?
Handler handler= new handler();
Thread t1;
t1=new thread(new runnable)){
void run(){
handler.postdelayed(this,2000);
}
}
这里的"this"指的是什么?
我知道 "this" 指的是 class 的当前实例,但这里的实例正在传递线程 class 或任何其他任何人都知道的关于此关键字的示例.请告诉我。
我是 android 的初学者。对我理清概念有很大帮助
您使用的 intent 函数以 Context 和 Class 作为参数,
Intent(Context packageContext, Class<?> cls)
因此这里的 this
是上下文。所以一般来说,如果您想使用当前的 class 作为上下文作为某些功能的参数,请使用 this
。
详细了解 Intent 构造函数 here
在第二个代码块中,this
指的是您希望函数 运行 打开的 Runnable class。
我建议你google关于函数或构造函数来回溯参数是什么。