First of all I have already added all the solutions from this link
Orientation Issue
I have 4 activities in my app and all of them are in landscape mode only. Flow in my app is
Login Screen>ProductScreen>VideoScreen
This flow works good. But there is a button on product screen which directs it back to the login activity to provide admin login functionality.
So when I click on this button, it navigates to login activity but it first shows up in portrait mode and switches back to landscape mode after sometime.
I have defined orientation both via xml as well as java class but it still happens.
All activities are opened with singleTask flag in xml.
Below is the related code
<activity
android:name=".activities.ActivityLogin"
android:screenOrientation="sensorLandscape"
android:configChanges="orientation"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And in onCreate() method I am doing this
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
Related
I am building an Android application that launches 3rd party applications - both of which run in full screen.
When the 3rd party application is launched, if i swipe up from the bottom, i see the Android navigation bar (good) - however, if i then press the Android Home button on this nav bar, the 3rd party application exits (good), but my application is returned to the main boot activity and not the activity from which i launched the application from.
My application manifest contains..
<activity android:name=".boot.BootActivity"
android:configChanges="keyboardHidden|locale|layoutDirection"
android:excludeFromRecents="true"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
<activity android:name=".main.MainActivity"
android:configChanges="keyboardHidden|locale|layoutDirection"
android:label="#string/title_activity_main"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden" />
The BootActivity performs a bunch of pre-loading and model generation before waiting for the user to select a button which starts loading MainActivity which displays the menus and synopsis for the 3rd party apps.
When 3rd party is launched, we swipe up and press Home on the Android nav bar, the logcat is getting both "android.intent.action.MAIN" and "android.intent.category.HOME".
As mentioned above, this is causing the app to return to the boot activity - but i would like the 3rd party app to exit and return to the apps synopsis in MainActivity.
Can intent-filters be added, removed or temporarily disabled programmatically?
Generally using these special launch modes (singleTask) is a bad idea. If your BootActivity is launching HomeActivity, then this will not run in a new task, even though the launch mode would imply that, because these activities both have the same taskAffinity. If you really want to have them run in different tasks, then you need to set the taskAffinity of one or the other (or both) so that they are not the same. Read a bit about how taskAffinity works.
I'm developing an Android app that needs to validate user with reCaptcha and I'm occurred on strange behaviour: if screen orientation is in landscape, tapping button that fires reCaptcha API orientation changhes to portrait and then back to landscape.
There is a way to fix this? I'm not found any documentation about this...
Here is API from SafetyNet lib:
SafetyNet.getClient(this).verifyWithRecaptcha(ReCaptcha.RECAPTCHA_APP_KEY)
Version:
implementation("com.google.android.gms:play-services-safetynet:17.0.0")
When you rotate your activity gets refreshed
You need to declare android:configChanges="orientation|screenSize" in activity tag
<activity
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
this will avoid activity refresh
I hope this will help
So I have an Activity A that is defined in the AndroidManifest.xml as defined below:
<activity
android:name=".activity.A"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This Activity launches a welcome Screen which we will call Activity B.
If you launch the application the Welcome screen is displayed and then once the user is done with it Activity A comes back.
The issue I am having is when I push the "Home" button from the welcome screen I go back to the Home Screen as expected. Now when I reclick on the Application Icon the application won't launch. Instead both my Activity A & B get destroyed. If I click on the icon again then the application relaunches as expected.
Now if I'm on the welcome screen and push the back arrow and reclick on the App icon it launches the application as expected. I don't have to push it twice.
Unfortunately I have to use the launchMode="singleTask" since it is a requirement for integration with another team. I have read the Android API's for Tasks and Back Stacks numerous times. Any pointers or suggestions would be greatly appreciated.
I came across a blog indicating there is an undocumented bug with using singleTask and intent-filters together but didn't find any official documentation on this.
Thanks
EDIT
Launching Activity B like this:
Intent intent = new Intent(context, B.class);
startActivityForResult(intent, CONST_VAR);
I tried making two activities which launches ActivityB from Activity A. I see no such problem as described in the question. PFB my manifest. Also, when you say home button, is it Phone home button or your app specific home button. PFB my manifest
<activity
android:name="com.android.testsingletask.MainActivity"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden"
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="com.android.testsingletask.WelcomeActivity"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden"
android:label="#string/app_name" >
</activity>
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"/>
In my application there is a behavior that I don't understand. I have the MainActivity A as SingleTask.
It calls an Activity B that is SingleTask too.
When I press the Home button in the second activity to open another application, and after that I try to go to my application mantaining Home button pressed i always go to Main Activity, and I want second activity to be opened mantaining the state that had when i press Home button.
I've tried setting then second activity to singleTop and it doesn't work.
Any help?
The behaviour of activity back stack becomes quit weird when define main activity with singleTask at the same time:
<activity android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
What even worse is there is no clear explanation in the official dev guide regarding to this special use case. Some sections related to this topic are even self-contradictory.
Try using launchMode="standard" on your MainActivity A, and launchMode="singleTask" on your Activity B, which will give the expect behaviour you described.