虽然我在 Stack Overflow 上搜索了很长一段时间,但到目前为止还没有找到我想要的答案。
一、问题描述:
- 我有一个包含大量活动的 Android 应用程序并提交到 Google Play。发布后,我下载了它,每当打开应用程序时,它都会启动一个新任务。我需要多次单击硬件后退按钮才能终止所有任务。而在那之后,每当我再次启动该应用程序时,一切都很好。
- 另一个奇怪的是,如果我通过adb命令直接在设备上安装应用程序没有问题(adb install xxxx.apk)
2. 我做了什么:
- 最初,在代码中,我使用“标准”启动模式进行启动活动。我遇到了上述问题。
- 看了官方文档,发现“标准”模式每次都会启动一个activity的实例,所以我把启动模式改为“singtop”,但问题依旧。
3. 我不明白的地方:
- 如果我从 Google Play 安装应用程序,为什么应用程序会不断创建新任务。为什么“Singtop”启动模式在这种情况下不起作用?
- 为什么直接通过 adb 命令安装应用程序时没有问题,而从 Google Play 安装应用程序时却遇到问题。有什么不同。
4.源代码供参考:
build.gradle(模块:应用程序):
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { applicationId "com.example.testing.exampletesting" minSdkVersion 17 targetSdkVersion 22 } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.0' }
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.testing.exampletesting" android:versionCode="10" android:versionName="1.0.1" > <application android:allowBackup="true" android:icon="@mipmap/app_logo" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" > <activity android:name=".LaunchActivity" android:launchMode="standard"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".DummyAActivity" /> <activity android:name=".DummyBActivity" /> <activity android:name=".DummyCActivity" /> </application> </manifest>