Android应用程序的多个实例打开-仅在Touchwiz上 [英] Multiple Instances of Android Application open - ONLY on Touchwiz

查看:119
本文介绍了Android应用程序的多个实例打开-仅在Touchwiz上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在为Android设备开发应用程序-我注意到一个困惑的问题,仅在运行Samsung Touchwiz的设备上会发生!

I have been working on an application for Android devices recently - and I have noticed a perplexing issue that only occurs on devices running Samsung Touchwiz!

当应用程序在 Touchwiz 设备上运行时,会发生错误.可以通过在应用程序处于前台状态时按后退"按钮来重现该错误-然后从主屏幕(或该图标可能位于其他任何位置)再次启动该错误.在多任务菜单中查看,很明显,系统启动了该应用程序的第二个实例!第二个实例与第一个实例完全独立,并且两者似乎没有以任何方式连接.

When the application is running on a Touchwiz device the bug occurs. The bug can be reproduced by pressing the "back" button while the application is in the foreground - and then launching it again from the home screen (or anywhere else the icon may be). Looking in the multi-tasking menu it is clear that the system launches a second instance of the application! This second instances is totally independent from the first instance and the two do not seem to be connected in any way.

我以为我可以通过向应用程序清单中添加singleInstance来防止此行为,但这似乎并不能解决问题. 清单:

I thought I could prevent this behavior by adding singleInstance to the applications Manifest, but this did not appear to do the trick. Manifest:

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

有趣的是,第二个实例在应用程序启动屏幕上冻结"-直到从多任务菜单中单击该第二个实例.

It is interesting to note that the second instance "Freezes" at the applications splash screen - until this second instance is clicked from the multi - tasking menu.

这是我处理初始屏幕的方式:

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

在主要活动中,我还超越了后退按钮的作用:

I also over-rode the back buttons action in my main activity:

public void onBackPressed()
{
    moveTaskToBack(true);
}

此错误 发生在具有TouchWiz的设备上.我已经在几种设备上测试了我的应用程序,除了运行TouchWiz的三星设备之外,此错误无法在任何设备上重现.

This bug only occurs on devices with TouchWiz. I have tested my application on several devices and this bug is not able to be reproduced on any device except for those Samsung devices running TouchWiz.

任何建议将不胜感激.

非常感谢!

推荐答案

问题似乎与mainactivity中的意图过滤器有关.从mainactivity中删除意图过滤器即可解决该问题.

The issue is seems to be with the intent filters in mainactivity. remove the intent filters from mainactivity that will solve the issue.

这篇关于Android应用程序的多个实例打开-仅在Touchwiz上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆