I am facing an issue in android application that Multiple instances of App are seeing in recent list.
<application
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.CEC"
tools:replace="android:theme,android:allowBackup,android:usesCleartextTraffic"
android:usesCleartextTraffic="false"
android:taskAffinity=""
tools:ignore="UnusedAttribute">
<activity
android:name=".ui.main.MainActivity"
android:configChanges="uiMode"
android:launchMode="singleTop"
android:taskAffinity="${applicationId}.MainActivity"
android:screenOrientation="portrait" />
<activity
android:name=".ui.splash.activities.SplashActivity"
android:exported="true"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity"
tools:replace="android:exported">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I am calling my method for recreating current activity for apply locale changes.
fun recreateActivity() {
val intent = getIntent()
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
intent.putExtra("activity_locale_changed",true)
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
finish()
startActivity(intent)
}
After implementing this code sometimes App is working fine or sometime app is creating multiple instances inside recent app list.
I have checked Multiple instances of app in recent app list of tablet(android),
Multiple Instances of the same app are generated in stack,
multiple instance of same app in android
Related
I am having 3 activities in my app and the flow is like A->B->C. When I was in activity C, I moved the app to background by pressing the home button. I brought the app to foreground again and it showed activity C as expected. When I press back key, it's closing the app and B and A are not shown.
I put the launch mode for A, C as single instance and for B, nothing is specified. I want to have one instance for all my activities. I have tried by changing the launch mode to single task(with permutation and combinations of all activities) and it didn't work.
Here is my manifest looks like for activity declaration
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
tools:ignore="GoogleAppIndexingWarning"
android:roundIcon="#mipmap/ic_myway_circular_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar">
<activity
android:name="A"
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="B"
android:windowSoftInputMode="adjustPan" />
<activity
android:name="C"
android:launchMode="singleInstance"
android:windowSoftInputMode="adjustPan"/>
</application>
Can someone tell me how to maintain the back stack always even when the app is opened from background?
Thanks in advance.
you can specify the parent(previous Activity) of any activity in the Manifest
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
tools:ignore="GoogleAppIndexingWarning"
android:roundIcon="#mipmap/ic_myway_circular_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar">
<activity
android:name="A"
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="B"
android:windowSoftInputMode="adjustPan" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".A"/>
</activity>
<activity
android:name="C"
android:launchMode="singleInstance"
android:windowSoftInputMode="adjustPan">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".B"/>
</activity>
</application>
After a lot of research, I found that it's the problem with the launch mode. As per Android documentation, for this mode, the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task
But I wonder the issue is only coming when the app brought to foreground from background. If it is continuously running on foreground, issue is not there.
Finally, I changed it to default mode and it's working now.
I have the following manifest:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme"
<activity
android:name=".LoginActivity" android:launchMode="singleTask" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".MainActivity" android:screenOrientation="portrait"/>
<activity android:name=".TaskDetailActivity" android:screenOrientation="portrait"/>
<activity android:name=".ConfigurationActivity" android:screenOrientation="portrait"/>
</application>
I don't know why, if I minimize the application and then i click on application icon, the app get relaunched instead of going to the last activity.
If I use application switcher instead of application icon for opening the application, It goes back to the last activity on use, so it works as expected.
Why is this behavior? I want to open the last activity when I click on application icon not restart the whole application.
An Activity with singleTask launchMode is allowed to have only one instance in the system.
Remove android:launchMode="singleTask" for more about singletask
I'm having an issue with deeplinking in my application. When I click a url from my email and it prompts me to choose an application to open the link with, my app is listed twice. One version works and the other does not. Any suggestions?
Here's the snippet of code I think could be the issue:
<application
android:name="com.test.TestApplication"
android:allowBackup="true"
android:fullBackupContent="#xml/backup_rules"
android:resizeableActivity="false"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.test.activity.LoginActivity"
android:configChanges="orientation"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" />
<activity
android:name="com.test.activity.HomeActivity"
android:configChanges="orientation"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.MenuDrawer">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
When an intent is sent to the system to open another activity, the system applies the rules specified here to find which activities/services can receive that intent. If there is more than one activity there, then the user will be prompted with all the matching activities. In this case what you experience is that the intent sent can be received (based on intent filters) by multiple activities, depending on how it is defined in your manifest.
I have an application that works like the UBER, it happens that when you're going on a run, the screen where the passenger accompanies the driver moving up to him, when the user will open other applications and attempt to return to the app by clicking on the main icon of the application that is in the launcher, the application returns to the first screen and not to the screen that was previously being screen is lost ...
My manifest.
<application
android:name=".Application"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:screenOrientation="portrait"
>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.RaceActivity" android:screenOrientation="portrait"></activity>
</application>
It is because you had used finish() in your java coding as i know if you use finish() for activity then it always finish your activity and when you will open app then it will start it from first screen .
After testing my application on multiple device i found out that on some of them if i click application icon it shows me
WelcomeActivity instead of bringing back the application from background. I know that WelcomeActivity is LAUNCHER but on my other devices the app icon alway bring me back the background application.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:launchMode="singleTop"
android:noHistory="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".WelcomeActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="#style/AppTheme"
android:windowSoftInputMode="adjustPan">
After WelcomeActivity i use MainActivity. and usually the app is putted to the background while that was alive.
Remove
android:launchMode="singleTop"
Because
If an instance of the activity already exists at the top of the target task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity.
Source