Android 应用程序的多个实例打开 - 仅在 Touchwiz 上
Multiple Instances of Android Application open - ONLY on Touchwiz
我最近一直在为 Android 设备开发应用程序 - 我注意到一个令人困惑的问题,该问题只发生在设备 运行 Samsung Touchwiz 上!
当应用程序 运行 在 Touchwiz 设备上时,会出现错误。当应用程序在前台时按 "back" 按钮,然后从主屏幕(或图标可能位于的任何其他位置)再次启动它,可以重现该错误。查看多任务菜单,很明显系统启动了应用程序的第二个实例!第二个实例完全独立于第一个实例,两者似乎没有任何联系。
我想我可以通过将 singleInstance 添加到应用程序清单来防止这种行为,但这似乎并没有起到作用。
清单:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:launchMode="singleInstance">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Settings_area"
android:screenOrientation="portrait" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDieXTCaFoIL0kJ_IM4UMBSQL3sNn92AWM" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" />
<activity android:name=".Splash"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".aboutPageActivity" />
<activity android:name=".turnOffFromNotification"
android:noHistory="true"></activity>
</application>
值得注意的是,第二个实例 "Freezes" 出现在应用程序初始屏幕上 - 直到从多任务菜单中单击第二个实例。
这就是我处理 启动画面的方式:
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, splashDisplayLength);
我还在我的主 activity:
中过度使用了后退按钮操作
public void onBackPressed()
{
moveTaskToBack(true);
}
此错误 仅 出现在具有 TouchWiz 的设备上。我已经在多个设备上测试了我的应用程序,这个错误无法在除那些三星设备 运行 TouchWiz 之外的任何设备上重现。
如有任何建议,我们将不胜感激。
非常感谢!
问题似乎与 mainactivity 中的 intent 过滤器有关。从将解决问题的 mainactivity 中删除 intent 过滤器。
我最近一直在为 Android 设备开发应用程序 - 我注意到一个令人困惑的问题,该问题只发生在设备 运行 Samsung Touchwiz 上!
当应用程序 运行 在 Touchwiz 设备上时,会出现错误。当应用程序在前台时按 "back" 按钮,然后从主屏幕(或图标可能位于的任何其他位置)再次启动它,可以重现该错误。查看多任务菜单,很明显系统启动了应用程序的第二个实例!第二个实例完全独立于第一个实例,两者似乎没有任何联系。
我想我可以通过将 singleInstance 添加到应用程序清单来防止这种行为,但这似乎并没有起到作用。 清单:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:launchMode="singleInstance">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Settings_area"
android:screenOrientation="portrait" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDieXTCaFoIL0kJ_IM4UMBSQL3sNn92AWM" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" />
<activity android:name=".Splash"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".aboutPageActivity" />
<activity android:name=".turnOffFromNotification"
android:noHistory="true"></activity>
</application>
值得注意的是,第二个实例 "Freezes" 出现在应用程序初始屏幕上 - 直到从多任务菜单中单击第二个实例。
这就是我处理 启动画面的方式:
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, splashDisplayLength);
我还在我的主 activity:
中过度使用了后退按钮操作public void onBackPressed()
{
moveTaskToBack(true);
}
此错误 仅 出现在具有 TouchWiz 的设备上。我已经在多个设备上测试了我的应用程序,这个错误无法在除那些三星设备 运行 TouchWiz 之外的任何设备上重现。
如有任何建议,我们将不胜感激。
非常感谢!
问题似乎与 mainactivity 中的 intent 过滤器有关。从将解决问题的 mainactivity 中删除 intent 过滤器。