What's the difference between this and Activity.this

后端 未结 4 1036
逝去的感伤
逝去的感伤 2020-12-01 06:49

For example

Intent intent = new Intent(this, SecondActivity.class);

eclipse error: The method setClass(Context, Class) in t

4条回答
  •  無奈伤痛
    2020-12-01 06:52

    Shubhayu's answer is correct, but I just want to make clear for anyone who see this question that this and Activity.this is the same if you are using it directly in the activity.

    This is answered here

    Example:

    @Override
    protected void onResume() {
        super.onResume();
    
        Log.d("Test", this.toString());
        Log.d("Test", MainActivity.this.toString());
    }
    

    Result:

    D/Test: com.example.app.MainActivity@e923587
    D/Test: com.example.app.MainActivity@e923587
    

提交回复
热议问题