I thought I had a good grasp of what I was doing but whenever I feel like I have a good handle on something, I'm proven wrong :)
The code in question is this
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mButton = (Button)findViewById(R.id.m_button);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
}
});
}
My confusion is in the new Intent()
and startActivity
method.
I was under the assumption that as long as we're working inside an anonymous class View.OnClickListener
that I'd have to do something like
MainActivity.this.startActivity(intent);
When I'm not inside the anonymous class, I can simply do
new Intent(this,SecondActivity.class);
Can someone explain why I am able to call the startActivity();
method but can't just use this
in the intent parameter?