how to not re-create itself after screen orientation change? - android

I created two layout folder in the layout-land,layout-port containing same files to pick layout depends on the mode change and i added this in my activity.
public void onConfigurationChanged(Configuration newConfig
{super.onConfigurationChanged(newConfig);setContentView(R.layout.main);}
and in manifest and android:configChanges="orientation";

<activity android:name = "DomainList"
android:configChanges = "keyboardHidden|orientation">
</activity>

Related

Orientation change notification in Android

Trying to follow something. Boiling down to simplest: In my AndroidManifest.xml I have the following:
<application
android:allowBackup="true"
android:configChanges="orientation"
...
</application>
In my activity that runs I have this:
#Override
public void onConfigurationChanged(Configuration newConfig) {
Log.d("PrimesAreInP", "onConfigurationChanged called");
}
However when I change the orientation of the phone from portrait to landscape I never see the onConfigurationChanged() print. What else do I need to do to see this call?
Try adding this for activity tag:
<activity android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboa‌​rdHidden"
I think you are missing this dude :
super.onConfigurationChanged(newConfig);
and not forget to write this line in activity tag of your menifest :
android:configChanges="orientation|screenSize"
good luck !!!

Locking orientation to portrait force close in my phone

I want my app to lock into portrait mode. For this I used this code :
<activity android:name="MyActivity"
android:label="#string/app_name" android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
>
and in MyActivity class :
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
This code work correctly in emulator, but when I install and run in my phone, the app is force closed.
How can I solve this problem?
Yo already use in manifest then there is no need to use by pragmatically. So remove the onConfigurationChanged method from your code.
I am using
android:screenOrientation="portrait"
in the manifest file, no other code in Java side and is working.
I see two problems here:
Remove android:configChanges="orientation|keyboardHidden" from manifest
Remove onConfigurationChanged from java
and it should work just fine

How to prevent Flurry change orientation of my activity?

One of my activities in my app has an android:screenOrientation="portrait" attribute in the manifest, as I don't want it to change orientation.
I'm trying to integrate Flurry like this:
in onStart:
FlurryAgent.onStartSession(this, "api_key");
FlurryAgent.initializeAds(this);
FrameLayout adsFrameLayout = (FrameLayout)findViewById(R.id.frameLayoutAdsContent);
FlurryAgent.getAd(this, "BannerTop-1", adsFrameLayout, FlurryAdSize.BANNER_BOTTOM, 0);
in inStop:
FlurryAgent.onEndSession(this);
and in the AndroidManifest.xml:
<activity
android:name="com.flurry.android.FlurryFullscreenTakeoverActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode"
android:screenOrientation="portrait" >
</activity>
What happens is that Flurry lets the activity to change orientation (when device is turned ti landscape). if I don't run the code in onStart the activity doesn't change its orientation.
thanks in advance,
Amitos80
What if you add: android:orientation="vertical" to the layout xml?
After a long research i found that this can't be done. flurry overrides my configuration and enables the screen to change orientation to landscape. if someone ever find a solution please share.

Disable screen rotating on Android [duplicate]

This question already has answers here:
How do I disable orientation change on Android?
(13 answers)
Closed 10 years ago.
When I press a button, I would like to disable screen rotation on all my activities. How can I do that?
BTW, the phone can be located in landscape or portrait position when the user click the button.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
You can change your AndroidManifest.xml to
<activity android:name="MainActivity" android:configChanges="orientation">
Which informs the OS that you will handle these config changes (by doing nothing.)
See How do I disable orientation change on Android?
I've found the solution:
in manifest.xml:
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:name="MyApplication">
in MyApplication.java:
public class UPackingListApplication extends Application {
public void onConfigurationChanged(Configuration newConfig) {
newConfig.orientation = [orientation we wanna to use (according to ActivityInfo class)];
super.onConfigurationChanged(newConfig);
}
}

Android - Vertical layout only

How do I make sure my app is only for vertical layout?
I have tried android:screenOrientation="portrait" but that doesn't seem to do the trick.
You need to add to all your activity not for one only. I think you understood that setting is per application wide, but it isn't.
<activity android:name=".MyActivity"
android:label="My Activity"
android:screenOrientation="portrait">
Add the declaration to the activity tag in AndroidManifest for every Activity you want to be portrait-only.
If you want some group of your activities to be locked on PORTRAIT mode only, than you can choose the next way:
public abstract class BasePortraitActivity extends Activity {
#Override
protected final void onCreate(Bundle state) {
super.onCreate(state);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
performOnCreate(state);
}
protected abstract void performOnCreate(Bundle state);
}
And than just extend BasePortraitActivity where you need it. Or just add setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); to YourActivity.onCreate().
you have to change into AndroidManifest.xml.
for each activity you have to insert:
android:configChanges = "orientation"
android:screenOrientation = "portrait"
for e.g.:
<activity android:name=".YourActivityName"
android:label="#string/app_name"
android:configChanges = "orientation"
android:screenOrientation = "portrait">
This works for a single activity.. But there seems no application wide setting there.
In your manifest under activity add this :
<activity
android:name="com.zeus.MyProject"
android:screenOrientation="portrait"
>
Activity is to block just in case want to block all and only repeat this line of code in their Activitys.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
// Here, talk to the java does not want that the user can rotate their activity.
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
or open your "AndroidManisfest.xml" and add the rows for the portrait mode as shown below.
android:configChanges="orientation"
android:screenOrientation="portrait">
Add android:configChanges="keyboardHidden|orientation" to the activity.
Put this attribute in layout root:
android:orientation="vertical"
It may help.
Just to confirm Pentium10's answer.
I was having a similar issue and adding android:screenOrientation="portrait" to the activity tag.
Did the trick for me.

Categories

Resources