-2

What does the keyword 'this' means in TextView textView = new TextView(this);

Below is quote sniplet

public class DisplayMessageActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_display_message);
        Intent intent = getIntent();
        String message = intent.getStringExtra(MyActivity.EXTRA_MESSAGE);
        TextView textView = new TextView(this);
        textView.setTextSize(40);
        textView.setText(message);
        setContentView(textView);
    }
    ....

My guess is it initialize the object textView but with what?

Eran
  • 387,369
  • 54
  • 702
  • 768
kcube
  • 47
  • 1
  • 3
  • 2
    That 'this' is just like always: a reference to the currently used instance of the class in which that method call is made. It simply passes 'itself' as parameter to that constructor. – Stultuske Feb 11 '15 at 12:10

1 Answers1

5

It's a reference to the current DisplayMessageActivity instance, which serves as a Context for the TextView.

Eran
  • 387,369
  • 54
  • 702
  • 768