use*_*996 24 java syntax android this android-activity
例如
Intent intent = new Intent(this, SecondActivity.class);
Run Code Online (Sandbox Code Playgroud)
eclipse错误:Intent类型中的方法setClass(Context,Class)不适用于参数(FirstActivity.ClickEvent,Class)
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
Run Code Online (Sandbox Code Playgroud)
但这是正确的.谁能解释这两者之间的区别?谢谢.
Shubhayu 的答案是正确的,但我只是想向看到这个问题的任何人澄清一下,如果您直接在活动中使用它,this则 和Activity.this是相同的。
例子:
@Override
protected void onResume() {
super.onResume();
Log.d("Test", this.toString());
Log.d("Test", MainActivity.this.toString());
}
Run Code Online (Sandbox Code Playgroud)
结果:
D/Test: com.example.app.MainActivity@e923587
D/Test: com.example.app.MainActivity@e923587
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13448 次 |
| 最近记录: |