Multiple Instances of Android Application open - ONLY on Touchwiz

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 03:55:26

问题


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!

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.

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.

This is how I am handling the splash screen:

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

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.

Any suggestions will be greatly appreciated.

Thank you very much!


回答1:


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



来源:https://stackoverflow.com/questions/38575165/multiple-instances-of-android-application-open-only-on-touchwiz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!