- 应用中响应
android.intent.action.MAIN
和android.intent.category.LAUNCHER
在本文中称为主界面。- 本文基于 Android O
问题现象
用PackageInstaller安装应用,在安装完成界面里点击打开,应用闪屏页打开后,按Home键回到桌面,点击桌面里的应用图标。
问题点:再打开一个闪屏页。
问题原因
应用中启动别的应用,以上问题场景使用的是 PackageManager#getLaunchIntentForPackage()
这个API,它的实现是:
// frameworks\base\core\java\android\app\ApplicationPackageManager.java
@Override
public Intent getLaunchIntentForPackage(String packageName) {
// First see if the package has an INFO activity; the existence of
// such an activity is implied to be the desired front-door for the
// overall package (such as if it has multiple launcher entries).
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_INFO);
intentToResolve.setPackage(packageName);
List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
// Otherwise, try to find a main launcher activity.
if (ris ==