私はアプリを持っており、2つのアクティビティがあります。インストール後にアプリを起動すると、差分動作(アンドロイド)があります
<activity android:name=".LauncherActivity"
android:theme="@style/LauncherTheme"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="MainActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"/>
1.(私は期待)
は、コマンドライン(ADB -rアプリをインストール)を介してアプリをインストールしてください。
起動するにはアプリアイコンをタップしてください。LauncherActivityが表示され、次にMainActivityにStartActivity、MainActivityが表示されます。
「ホーム」をタップし、もう一度「アプリ」アイコンをタップすると、「メインアクティビティ」が再び表示されます。
2.(例外?)
packageinstallerでアプリをインストールします。
インストールが完了したら、パッケージインストーラの「開く」ボタンをタップし、LauncherActivityと表示されたら、MainActivityにStartActivity、MainActivityと表示されます。
「ホーム」をタップし、もう一度アプリアイコンをタップすると、LauncherActivityが再び表示されます!私は源泉に見て、packageinstaller mLaunchIntent
で活動を開始し、私のLauncherActivity
private void startMainActivity() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
で
InstallAppProgress.java
mLaunchIntent = getPackageManager().getLaunchIntentForPackage(mAppInfo.packageName);
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 == null || ris.size() <= 0) {
// reuse the intent instance
intentToResolve.removeCategory(Intent.CATEGORY_INFO);
intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
intentToResolve.setPackage(packageName);
ris = queryIntentActivities(intentToResolve, 0);
}
if (ris == null || ris.size() <= 0) {
return null;
}
Intent intent = new Intent(intentToResolve);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(ris.get(0).activityInfo.packageName, ris.get(0).activityInfo.name);
return intent;
}
私は情報活性を持たないので、意図は次のとおりです。
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
intentToResolve.setPackage(packageName);
私は混乱しています。なぜ違いがあるのでしょうか?助けて!経由
異なる意図は、アプリが起動される方法に応じて発射されるので、これがあるif (!isTaskRoot()) {
final Intent intent = getIntent();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(intent.getAction())) {
finish();
return;
}
}
(オープン:これはまだあなたのための問題ですが、私は私のMainActivityでこれを含めることによって、これを解決した場合