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
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.
Suppose i have 3 Activities A, B, & C.
If i go A->B->C then if i hit the recent apps button it is not showing the latest screen in the recent apps lists which should be C. However if i press Home button and then press the recent tasks is shows the Activity C. Then works fine. But then again if i got from C->B->A then again if i press the Recent tasks it shows the Activity C which should be Activity A.
i cant find the pattern of this must be some thing with the Manifest file
<application
android:name=".App"
android:allowBackup="true"
android:icon="#mipmap/logo_main"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/themex">
<activity
android:name=".SplashScreen"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".StartingActivity"
android:screenOrientation="portrait"
android:theme="#style/theme1"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/themex"
android:windowSoftInputMode="stateAlwaysHidden" />
</application>
So i figured out the answer after few tries...i have set
<item name="android:windowIsTranslucent">true</item>
in my theme which causes the problem. i removed it and it works fine.
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
In AndroidManifest.xml, the application tag has:
android:label="#string/app_name"
and app_name in res/values/strings.xml reads "My App".
But after running or debugging on both the emulator and an attached device, the app icon on the home screen displays the main activity's label instead of the app label. Is this expected behavior, and if not why might it be happening?
Yes it is Expected behavior. The app name will be seen in the applications tab in settings. The main screen displays the launcher activity's label.
If you want to display the app_name property as the label of your application below the launcher icon you can specify the android:label property in the application tag of your android manifest file.
For example:
<application
android:name=".MyApp"
android:icon="#drawable/myIcon"
android:label="#string/app_name">
A workaround for this behaviour:
In manifest:
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In MainActivity's onCreate:
getSupportActionBar().setTitle(R.string.activity_name);
By doing this, the app name will appear on home screen, and you can still have a different title for your launcher activity.
People see here, I got the same issue and finally resolve it.
Launcher show only the mainActivity because activity label is preferred for Phone Launcher.
So one want show Application labe rather than MainActivity's, he should delete the line:
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter android:label="#string/app_name" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
delete this:
android:label="#string/title_activity_main"