Can a live wallpaper lock the screen in portrait mode? - android

Can a live wallpaper lock the screen in portrait mode? And if so, how?
I should mention that I have seen two supposed answers to this question on SO, one appeared inordinately complicated, I didn't understand it all and the answer was not accepted by the original poster. The second answer didn't work for me.
A third answer involving the use of:
android:screenOrientatin = "portrait" or "landscape"
has been suggested, but it is not clear exactly where this should go in the manifest.
EDIT: have tried putting android:screenOrientation="portrait" in many different places in the manifest, and none of them worked.
EDIT: another answer was to rotate your bitmaps and handle a rotation by just drawing everything sideways - but this looks very ugly because, as you rotate you phone, the OS instigates a rotation animation - which means that you get a horrid jumping effect as you turn the phone.

I'm beginning to suspect that the true answer is simply "no".

Did you try setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ?

In your AndroidManifest.xml you should have something like:
<application
android:icon="#drawable/app_icon"
android:label="#string/nuboLogin"
android:name=".LoginApplication"
android:debuggable="true">
<activity
android:name=".WallPaperActivity"
android:label="#string/wallPaper"
android:windowSoftInputMode="adjustPan"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
This should make sure that your Activity runs in portrait mode. If you prefer landscape, you can easily guess what you should modify

Android application restarts the activity when the orientation changes. You can either use
android:configChanges in your manifest. The activity is shut down and restarted by default, when a configuration change occurs at runtime, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.
use android:screenOrientatin = "portrait" or "landscape" it will force the app to run in the mode you specify. However it will not prevent the activity from being shut down and restarted.

Related

Screen still can rotate even if orientation is set to Portrait

I know the tile seems to be very confusing, but yeah, it happened to my application. Ok, here's the story.
Here's the key settings in Manifest:
android:screenOrientation="portrait"
android:configChanges="orientation|screenSize|keyboardHidden"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
In my Activity.java, I also override onConfigurationChanged(Configuration config), which will print out current orientation.
Here comes the most interesting part. I start a rotatable Application, say Gallery (assume it can rotate), from my application in landscape using Intent. Keep the phone in landscape, and press back key. The newly launched activity, in this case Gallery, will quit, and my application will restart. In theory, my application should display in portrait since I have set the screenOrientation to portrait. However, in reality, my application just stays in portrait for 1 second, and then jumps to landscape, and jumps back to portrait again.
I start a thread to print out requestedOrientation of my application after onRestart is called. And I find out that the output is always "1", which is "portrait". Yet, the output from onConfigurationChanged gives my a current orientation of landscape!
So, I'm totally confused. How can this happen? Can someone give me some advice?
May be you use screen orientation in an activity. But another activity will be rotate. in below example ActivityA's orientation will not change but ActivityB will be rotate. If you write android:screenOrientation="portrait" in app tag and not mention anything in activity. It doesn't work anything. So please mention screenOrientation in activity.
<activity
android:name=".ActivityA"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".ActivityB">
</activity>
are you using android:screenOrientation="portrait"
android:configChanges="orientation|screenSize|keyboardHidden"
inside your application or under activity

Screen orientation forced to portrait, but still, the activities will rotate to landscape when tilted!! How to force portrait mode?

I've searched stackoverflow for this and didn't get any solution to what I am looking for.
In my manifest file I am writing the following line for each activity
android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"
But still, all the activities rotate to landscape on tilting the phone.
How can I solve this issue ?
"Once upon a time I was a confident developer in C/C++,iOS,Java,Javascript,C# but thank you android! now I can't even look eye to eye in mirror!"
May be this will help
In your manifest file after your main activity write below line
android:screenOrientation="portrait"
Or in your coding after setContentView() add this line..
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Prevent app from restarting during orientation change

I have a canvas, and it is redrawn when orientation is changed. It's a custom canvas not android provided.
When screen layout is changed, application state and (all of it's view's states) gets reset. I changed screen orientation to portrait only; it keeps screen layout unchanged but application is again resetted.
I checked documentation and found that activity is destroyed and restarted again when orientation change occurs. Savestate() cannot save and load bitmap data or any large data which are required by my custom canvas.
I again checked documentation, and found Handling run time changes topic, which mentioned onConfigurationChanged() which gets called when specific configuration change is occurred, which in my case is 'orientation'. This method prevents restart and leaves to developer how that configuration change should be implemented. It even mentioned in last paragraph that if I will not implement that method then this will just cause the activity to skip onRestart() and will do nothing. I am setting manifest file as
android:screenOrientation="portrait"
android:configChanges="orientation"
And I am not implementing onConfigurationChanged(). But this doesn't help either. I don't know why. It seemed so helpful to me.
Please post solution if you have any.
Also, app takes some resonable time, and I would like app do not restart when orientation is changed. Actually I don't want to do anything when this happens.
I am using emulator too, so please clarify if it is emulator only problem.
P.S. My internet connection is down and I am using my stupid mobile client.
I have checked the offline documentation. And please bear with me for spellings. I am trying to find solution, but currently I am stumpped.
Use this in you AndroidMenifest.xml
<activity
android:name="MyActivity"
android:configChanges="orientation|keyboard|keyboardHidden"
android:screenOrientation="sensor" />
write this code in manifest:
android:configChanges="orientation|screenSize|keyboardHidden"
For each activity in the AndroidManifest, the screenOrientation can be specified. For example, to specify that the activity always stays in portrait mode, the following can be
added to the activity element:
android:screenOrientation="portrait"
Similarly, landscape mode can be specified using the following:
android:screenOrientation="landscape"
However, the previous still causes the activity to be destroyed and restarted when a hard
keyboard is slid out.Therefore, a third method is possible:Tell the Android system that the
application should handle orientation and keyboard slide-out events.This is done by
adding the following attribute to the activity element:
android:configChanges="orientation|keyboardHidden"

can i allow an android activity to change to landscape only on certain conditions?

most of my application will not look so well on landscape, but that's the user choice as far as i'm concerned if to see the application on 'wide' screen.
However i have an auto complete screen and that screen cannot function in landscape mode since when user input text and i bring the results into the list view on screen the user can't see the listview since the virtual keyboard covers it all.
So i thought of defining in the manifest that this activity wont be used in landscape, but i CAN use it in landscape mode for devices with hardware keyboard that is open...
So either i can define it in the manifest (couldn't find how) or i need to do it melodramatically (discover the keyboard existence and open to support it, or disable the rotation otherwise).
Anyone knows how to do that ?:
You can try
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
OR
activity android:name=".SomeActivity"
android:screenOrientation="portrait"
these may help you.
you can also intercept these config changes:
<activity ...
android:configChanges="orientation|keyboardHidden">
</activity>
and in onConfigurationChanged() you can decide what to do with them.

Android orientation issue

I have application which works only in landscape orientation . I set that in xml layout. When I'm starting application it works ok . But when the application is started and next if I lock the phone and then unlock, the application first 1-2 seconds is in portrait mode and then in landscape. Is it possible to skip theese 2 seconds?
Try defining it explicitly in your manifest. Add android:screenorientation="portrait" to each <activity> element.
Not to be a downer, I really hope you solve this. Just wanted to throw out there that I have noticed this sort of behavior(typically for me the apps are supposed to stay in portrait but they show landscape for about 2 seconds) on multiple applications on my Sprint HTC Hero, including the default home application and many of the default included apps (contacts, etc). I am beginning to suspect it's an android problem. Again, feel free to disagree with me, but I just wanted to say that I have noticed this on a lot of apps & you're not alone here :/ However, there are some apps that I have not noticed it on, so either a) I am just getting lucky or b) there is a correct solution
Execute this in your onCreate(), just before setcontentview:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
I use this method in my apps and I never notice the orientation changing. It's locked solid into the requested orientation.
To be provocative, actually, what he needs to put in each activity element in his manifest is:
android:screenOrientation="landscape"
and not "portrait"
:P
I hope this help; put these on every activity-element in your Android Manifest-file.
android:configChanges="orientation"
android:screenOrientation="landscape"
Of course it is landscape; my brain was not the quickest this time.

Categories

Resources