Intent:通过使用 getApplicationContext() 实例化 Intent 时避免内存泄漏?

Intent: Avoiding memory leaks when one instantiates an Intent, by using getApplicationContext()?

在官方文档中(https://developer.android.com/reference/android/content/Intent.html#Intent(java.lang.String,%2520android.net.Uri为方法public Intent (Context packageContext, Class<?> cls),我们可以读到:

packageContext Context: A Context of the application package implementing this class.

这个 Whosebug 答案 What's packageContext in Intent#(Context packageContext, Class<?> cls)? 精确说明了这个定义的含义:

You can pass any Context object you got from any of you application's classes. So you can either use an Activity, Service object or you can call getApplicationContext() and pass the returned Context object to the Intent constructor.

即使 Intent 的生命周期很短,我们是否应该使用 getApplicationContext 而不是 getActivity 以避免内存泄漏(这样我们就可以避免保留引用到 activity,可以将其从 RAM 中删除)?

示例,在片段 class 中,在创建 activity 之后调用以避免 NullPointerException:

startActivity(new Intent(getActivity().getApplicationContext(), SplashScreen.class));

没关系,上下文不是 "held" Intent。只是用来查东西的(iirc,包名)。