【发布时间】:2016-10-18 03:18:35
【问题描述】:
我刚刚了解到我可以使用任何一种:
Toast.makeText(MainActivity.this, R.string.some_string,Toast.LENGTH_SHORT).show();
或者,
Toast.makeText(getApplicationContext(), R.string.some_string,Toast.LENGTH_SHORT).show();
在 Android 中显示 Toast。
之前我认为上下文实际上是父窗口的一种句柄,但 documentation 对此并不清楚。
它似乎也没有提到 Toast 到底使用什么上下文?
编辑:
上下文是否像 Toast 这样的子窗口的“父窗口句柄”?还是它实际上允许Toast.makeText 访问资源或其他东西?
如果上下文无关紧要,为什么还要使用它?
【问题讨论】:
-
Activity 的上下文。对于用户界面,请始终使用活动的上下文
标签: android android-context android-toast