I'm learning some android development. The following is just a simple code of a multi-screen app for users to click and to change to another screen.
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView redio = (TextView) findViewById(R.id.activity_redio);
redio.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
Intent redioIntent = new Intent(MainActivity.this, redio.class);
startActivity(redioIntent);
}
}
);
}}
It works well. But I have a question about the 'startActivity(redioIntent);' method. Unlike setOnClickListener() method or other general methods in JAVA, I don't need to declare a new instance in order to use it. I wonder why? Moreover, how do I distinguish which methods require declaring new instances and which don't?
Another question is, When creating an new Intent, What does 'this' referees to and what does redio.class mean? I checked the documentation on android developer. It says MainActivity.this is an context. But what is context? And why does Intents need context and class to creat?