java - Android 应用程序的多个实例打开 - 仅在 Touchwiz 上

标签 java android android-manifest multiple-instances samsung-touchwiz

我最近一直在开发适用于 Android 设备的应用程序 - 我注意到一个令人费解的问题,它只发生在运行 Samsung Touchwiz 的设备上!

当应用程序在 Touchwiz 设备上运行时,会出现错误。当应用程序在前台时按“后退”按钮,然后从主屏幕(或图标可能位于的任何其他位置)再次启动它,可以重现该错误。查看多任务菜单,很明显系统启动了应用程序的第二个实例!第二个实例完全独立于第一个实例,两者似乎没有任何联系。

我认为我可以通过将 singleInstance 添加到应用程序 list 来防止这种行为,但这似乎并没有起到作用。 list :

  <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>

有趣的是,第二个实例“卡住”在应用程序启动屏幕上 - 直到从多任务菜单中单击第二个实例。

这就是我处理启动画面的方式:

 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 过滤器。

关于java - Android 应用程序的多个实例打开 - 仅在 Touchwiz 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38575165/

相关文章:

java - 如何在本地网页(在我的 PC 上)上使用 Selenium WebDriver 而不是位于在线某处的网页?

java - 将 POJO 序列化为 json,并将某些值作为字符串或列表

java - 如果使用spring注入(inject)mapper,mybatis session 什么时候打开?

android - 使用动画让图像扩展到 View 中

android - 正确使用 <intent-filter>

Java 二进制文件未从指定的类路径获取资源

java - 致命信号 11 (SIGSEGV),代码 1,tid 13934 中的故障地址 0x40

Android 媒体编解码器 : Reduce mp4 video size

android - 未捕获的异常重新启动调用 Activity ?

android - Google Play 不显示我的平板电脑应用程序