what will happen if add screenOrientation=behind into launch Activity element
<activity
android:name=".ui.activity.SplashActivity"
android:screenOrientation="behind"
android:configChanges="screenSize|orientation|keyboard"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
I want to know what will happen if I write this , and want to know the details.
If you are set all activity of your project in the same screenOrientation. you can start your application with a splash screen activity, set the orientation like in your current code and forward to your CoreActivity or any other activity in your App.
In your AndroidManifest.xml set
<activity
android:name=".CoreActivity"
android:screenOrientation="behind"/>
This will use the same orientation as the activity that's immediately beneath it in the activity stack.
Explicitly it's used to Keep the screen in the same orientation as whatever is behind this activity.
Related
I Have the Code in manifest:
<activity android:name=".activities.login.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.main.screen.MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
What is happening:
The i load the app for the first time (Ex: Install it from
androidStudio) 'MainActivity' is loaded but once i close and launch
again LoginActivity is launched everytime
This happens for the first time
MainActivity launching happening for the first time
Its should always load 'LoginActivity' right since my launcher is
'LoginActivity' why is LoginActivity loaded just for first time. Is
there any setting i need to check
You have used
android:launchMode="singleTop"
in your main activity. According to docs -
if an existing instance of the "singleTop" activity is in the target task, but not at the top of the stack, or if it's at the top of a stack, but not in the target task — a new instance would be created and pushed on the stack.
So that's why MainActivity is loading.
You should remove
android:launchMode="singleTop"
to get desired results.
For more information on launch modes refer docs -
https://developer.android.com/guide/topics/manifest/activity-element
There is an Activity named PlayActivity which is used to play videos, and I set this activity to use the landscape model by xml:
<activity
android:name=".activity.PlayActivity"
android:screenOrientation="landscape">
Now once I enter the activity from another Activity say it is MainActivity, the PlayActivity will use the landscape model as expected, however once I hit the back button to return to MainActivity, I found that the MainActivity is changed to landscape too, how to avoid this?
Try to put your MainActiviy activity in the portrait, since you can configure the whole application in one direction to customize each one of them to leave an example of how serious greetings.
<activity
android:name=".activity.MainActivity"
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=".activity.PlayActivity""
android:screenOrientation="landscape"
/>
I have an activity 'A' defined in Manifest like below:
<activity
android:name=".A"
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>
When I launch my APP, that activity is always loaded from the start. It wont start from my prev activity.
When I remove android:launchMode, then it works as I expect.
Since you set android:launchMode="singleTask", the activity A will always be the root of your activities.
From DOCS:
In contrast, "singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack. Moreover, the device can hold only one instance of the activity at a time — only one such task.
Default mode is standard. So, when you remove android:launchMode="singleTask", your APP returns to standard launch mode.
That's why if you app is always starting Activity A.
If you would like to start a different Activity on launch replace that in the xml name attribute that contains LAUNCHER
<activity
android:name=".ActivityB"
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>
Where Activity B is an alternate activity.
Activity A is a splash screen.
Activity B is a menu screen that is singleTask.
Activity C is a screen with noHistory that selects a photograph from the gallery with the built-in intent for choosing a photograph.
Activity D is a screen that manipulates photographs.
The problem that I have is that when I am in Activity D and select the home button, if I choose the application to be launched once more it returns me to Activity A to launch Activity B again instead of launching Activity D where I left off. If I use the recent apps however, it switches back to Activity D just fine as expected. So, there must be something slightly error prone in the way that I have it setup. But, I should expect it to return to Activity D in both cases so that the user can keep coming back to the Photo viewing screen (Activity D).
Thoughts?
<activity
android:name="ActivityA"
android:theme="#style/Theme.CustomDefaultStartup"
android:noHistory="true"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="sensorLandscape"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="ActivityB"
android:theme="#style/Theme.CustomDefault"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="#xml/device_filter" />
</activity>
<activity
android:name="ActivityC"
android:theme="#style/Theme.CustomDefault"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name">
</activity>
<activity
android:name="ActivityD"
android:theme="#style/Theme.CustomDefault"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name">
</activity>
Apparently it was the android:launchMode="singleTask" on Activity A that was causing the problems. Once, the singleTask from the splash screen was removed, the behavior returned as was expected. Not sure where the singleTask for the splash screen came from, but it was probably an error left in place for a while in the application.
Once that was removed, Activity D no longer launched the splash screen and the following menu after a home button press and return to the application. While I do not follow this completely as to why this would cause it in the lifecycle of events, this resolved the issue for me.
I have some troubles with spash screen. When I launch app, splash screen activity launches for some seconds. After it main activity launches.
And if i press home button on the main activity and then relaunch app from apps list, splash activity launches again although the app is already in backstack. But I expect main activity to restore from memory.
And if i press back button after that android returns me to the previous copy of main activity.
What I have to do to make splash screen appear just once? And how to get my app relaunched from the last screen I saw before the home button was clicked?
<activity
android:name=".ui.SplashActivity"
android:noHistory="true"
android:screenOrientation="portrait"
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.MainActivity"/>
This is a design problem. Your launcher activity should not be your splash screen activity. Instead, open your splash activity in your main activity's onCreate method. That way, if it is opened fresh, onCreate is called and the splash screen is shown. Otherwise, if the app is merely resumed, which calls onResume, there would be no call to open the splash screen activity.
Then you can change your manifest to this:
<activity
android:name=".ui.MainActivity"
android:noHistory="true"
android:screenOrientation="portrait"
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.SplashActivity"/>