Activity orientation restore - android

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"
/>

Related

what will happen if add screenOrientation=behind into launch Activity element

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.

Screen rotate 3 times when back to landscape activity from portrait activity

I have this issue in my tablet device Android 8.1. This device has natural orientation is landscape
I have 2 activity :
A is configured with fullSensor, contains a recyclerview to load items with thumbnail image
B is portrait, contain a surfaceview
<activity
android:name="com.hdq.myapp.activities.AActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.hdq.myapp.activities.BActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="fullSensor"
android:theme="#style/AppTheme.NoActionBar">
Step 1 : Open activity A in landscape -> start Activity B : it rotate
to portrait
Step 2 : Press Back button, it return to activity A and rotate to
landscape
Step 3 : After that, it keep rotate to portrait immmdiately
Step 4 : Finally, it rotate to landscape again. 3 rotation in just 2 second
It's seem less happen out if A and B is very simple activity (no recylerview, no surfaceview). Just less than before.
This behavior is too weird and I'm not sure where it come from, maybe OS or somewhere my app. The onConfigurationdChanged() method was called 2 time. Another apps in this device are not happen like this. Do you have any idea about this? Is that a memory issue or something like that?
I update the profiler in my device :
The red one is the first normal rotation. 2 yellow ones is redundant.
This is call chart :
Try this:
<activity
android:name="com.hdq.myapp.activities.AActivity"
android:configChanges="locale|keyboard|keyboardHidden|orientation"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize|screenSize"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.hdq.myapp.activities.BActivity"
android:configChanges="locale|keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
android:theme="#style/AppTheme.NoActionBar">

singleTask activity not loading properly

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.

When using taskAffinity to have multiple Activities in the Launcher for the same app, if one is active the other needs to be clicked twice

Scenario:
Two Activities being shown in launcher for one app, they have different taskAffinities because I was getting the problem of when I open one, hit home, open the other, the first one would be opened. So, I added taskAffinity in the AndroidManifest for the proper tasks.
The problem I'm getting is that if I open one, hit home, hit the second one, it will open the proper task/Activity, BUT I have to click on the icon twice in order for it to open and get, this ONLY happens with the activity that specifies a taskAffinity, the other one opens just fine on the first click every time.
731-1337/? W/InputMethodManagerService﹕ Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#4e640b6 attribute=null, token = android.os.BinderProxy#3edac0ca
Here is the manifest
<activity
android:name=".firstActivity"
android:theme="#android:style/Theme.Holo.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".secondActivity"
android:label="#string/second_activity"
android:icon="#drawable/ic_second_activity"
android:taskAffinity="secondTask"
android:theme="#android:style/Theme.Holo.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".thirdActivity"
android:label="#string/second_activity"
android:taskAffinity="secondTask"
android:theme="#android:style/Theme.Holo.Light.NoActionBar"/>
I fixed this by adding this to the thirdActivty which was being called by secondActivity immediately on launch.
android:launchMode="singleTask"
So it ended up looking like
<activity android:name=".thirdActivity"
android:label="#string/second_activity"
android:taskAffinity="secondTask"
android:launchMode="singleTask"
android:theme="#android:style/Theme.Holo.Light.NoActionBar"/>
Hope someone finds this solution helpful.

After home button and returning, it does not return to previous 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.

Categories

Resources