区别以及何时使用getApplication(),getApplicationContext(),getBaseContext()和someClass.this
我是新来的Android和我想明白之间的差别getApplication(),getApplicationContext()getBaseContext(),getContext()以及someClass.this特别是当使用这些方法在下面的代码行: 当我敬酒时,这些和在什么情况下使用它们有什么区别? 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(); 与意图相同: 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);