la diferencia y cuándo usar getApplication (), getApplicationContext (), getBaseContext () y someClass.this
Soy nuevo en Android y estoy tratando de entender la diferencia entregetApplication()
, getApplicationContext(
)getBaseContext()
, getContext()
ysomeClass.this
y especialmente cuando se usan estos métodos en las siguientes líneas de código:
Cuando lanzo un brindis, ¿cuál es la diferencia entre estos y en qué casos los uso?
Toast.makeText(LoginActivity.this, "LogIn successful", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplication(), "LogIn successful", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "LogIn successful", Toast.LENGTH_SHORT).show();
Toast.makeText(getBaseContext(), "LogIn successful", Toast.LENGTH_SHORT).show();
Lo mismo con intenciones:
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
Intent intent = new Intent(MenuPagina., LoginActivity.class);
Intent intent = new Intent(getBaseContext(), LoginActivity.class);
Intent intent = new Intent(getApplication(), LoginActivity.class);