【发布时间】:2018-01-31 16:08:48
【问题描述】:
我有一个用作启动器的应用程序。此应用有 3 个活动:
-
SplashActivity:加载时显示启动画面,然后启动LauncherActivity并完成。这是清单中标记为启动器的 Activity。startActivity(Intent(this, LauncherActivity::class.java)) finish() <activity android:name=".SplashActivity" android:label="@string/app_name" android:screenOrientation="landscape" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> -
LauncherActivity:Launcher 的主要活动。有一个启动DashboardActivity的菜单按钮。startActivity(Intent(this@LauncherActivity, DashboardActivity::class.java)) <activity android:name=".LauncherActivity" android:launchMode="singleTask" android:screenOrientation="landscape" /> -
DashboardActivity:显示应用列表并通过其启动意图启动它们。private val DEFAULT_FLAGS_APP_LAUNCH = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(packageManager.getLaunchIntentForPackage(packageInfo.packageName).apply { flags = DEFAULT_FLAGS_APP_LAUNCH }) <activity android:label="@string/apps" android:theme="@style/TNA" android:name=".DashboardActivity" android:launchMode="singleTask" android:screenOrientation="landscape" />
所有活动都是通过startActivity 启动的,包括应用程序。
我想要标准的 Android Launcher 行为,即:当通过DashboardActivity 进入应用程序时,如果我单击主页按钮,则转到主 Launcher 活动(LauncherActivity),然后单击返回时,转到仪表板(DashboardActivity)。
我遇到的问题是,当点击主页时,它会回到DashboardActivity,而不是LauncherActivity。如果我完成DashboardActivity,那么当点击一个应用程序时,它会返回到LauncherActivity。
关于如何解决这个问题的任何想法?
【问题讨论】:
-
您能否围绕您的意图转换和 android 清单显示一些代码?否则很难说你是如何操纵后台堆栈的。
-
@Submersed 我尝试了很多启动选项和标志都无济于事。我会用代码更新问题。
-
好酷,所以你是启动器屏幕,我现在明白了。