这让我难住了,我在Android 2.1-r8 SDK中使用这个:
ProgressDialog.show(getApplicationContext(), ....);
还有在
Toast t = Toast.makeText(getApplicationContext(),....);
使用getApplicationContext()同时崩溃ProgressDialog和Toast ....这让我想到了这个问题:
活动上下文和应用程序上下文之间的实际区别是什么,尽管都使用“上下文”这个词?
我发现这个表格对于决定何时使用不同类型的上下文非常有用:
An application CAN start an Activity from here, but it requires that a new task be created. This may fit specific use cases, but can create non-standard back stack behaviors in your application and is generally not recommended or considered good practice.
This is legal, but inflation will be done with the default theme for the system on which you are running, not what’s defined in your application.
Allowed if the receiver is null, which is used for obtaining the current value of a sticky broadcast, on Android 4.2 and above.