android - 已完成的启动活动在启动器上重新启动
问题描述
我有一个简单的应用程序,其中包含两个活动,一个显示动画的启动活动,然后启动一个 singleTop 着陆活动(通过通知处理打开应用程序)并完成。当应用程序从启动器启动时,即使应用程序已经在运行,也会再次调用该启动活动。同样奇怪的是,当我调试应用程序时,这种行为永远不会发生,只有安装了已发布的 apk
飞溅活动
<activity
android:name=".SplashScreen"
android:exported="true"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:stateNotNeeded="true"
android:theme="@android:style/Animation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
导航到着陆活动并完成
private void navigateToLandingScreen() {
Intent intent = new Intent(SplashScreen.this, LandingActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.splash_fadein, R.anim.splash_fadeout);
finish();
}
使用 singleTop 启动模式登陆活动
<activity
android:launchMode="singleTop"
android:name=".LandingActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"/>
解决方案
试试这样:
overridePendingTransition(R.anim.splash_fadein, R.anim.splash_fadeout);
finish();
SplashScreen.finish();
推荐阅读
- sequelize.js - 使用 Sequelize / PostgreSQL 使用 NestJS 上传表单数据
- ios - React Native FBSDK IOS 构建失败
- python - Matplotlib 仍未安装在 v3.8.6 的 python 上。(之前我在 v3.9 上)
- linux - Linux Kernel上游驱动的源码结构要求
- yaml - 如何在 YAML 管道中指定 .NET Framework 版本?
- python - 如果满足条件,则使用列名更新行值
- encryption - 在 oracle 中解码 sh256
- reactjs - 在反应中将 sass 样式转换为内联样式对象
- r - 删除多年范围内的所有日期
- java - 获取异常表间歇性地处于只读模式