简体   繁体   中英

After pressing home button new Instance of application starts . How to avoid to create multiple instance of Application

I am facing an issue that ,When ever I start the app and press home button ,then again I click the apps icon a new instance of that app is created . How to solve this issue ?

My Manifest file as follows ,

    <activity
        android:name="com.example.mytast.MainActivity"
        android:label="@string/app_name" 

         android:screenOrientation="portrait"

         android:configChanges="orientation|keyboardHidden"

          android:alwaysRetainTaskState="True"
         >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Add:

<activity
   android:name="com.example.mytast.MainActivity"
   android:launchMode="singleTask"
   ...
   >  
</activity>   

and remove:

android:alwaysRetainTaskState="true"

from the directive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM