I'm using tab widget.
When my child activity is running and I change the orientation,child activity destroy.
As a solution of this problem,I added
android:configChanges="orientation|keyboardHidden in all activity tags in my manifest.xml file.
I found that my app doesn't take xml file from layout_land folder.
Can anyone give me solution for this query?
Thanks in advance.
I found that using onConfigurationChanged method i can know the orientation and i have to set landscape file in layout folder instead of layout_land folder.
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
setContentView(R.layout.login_landscape);
}
else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.login);
}
}
This happens because your Activity is not destroyed since you have put android:configChanges="orientation|keyboardHidden" in manifest so the setContentView is not called when orientation changes and therefore it doesn't pick the layout from the layout_land
Update : And this is not a problem with your Tab-Activity try it in normal activity it will not pick the correct layout or in general speaking no layout is picked your portrait layout is only rotated to be displayed in landscape
Related
I have this situation.
A drawer layout -> each section is a fragment
A section contain a page viewer (3 fragments )
Each fragment contains a recyclerview and each item is a fragment
I have some problems.
When the orientation of the screen changes i move always to the first fragment of the page adapter.
If i write something in one of these fragments and the sceeen orientation change lose everything.
Same problems with onPause etc.
How can I manage this situation?
thanks.
Make sure the you are using getChildFragmentManager() instead of getFragmentManager()/getSupportFragmentMAnager() inside a nested Fragment.
Maybe it's will be helpful. Just paste it in your AndroidManifest file
android:configChanges="orientation|keyboardHidden|screenSize"
Add this android:configChanges="keyboardHidden|orientation|screenSize">
inside activity of your AndroidManifest.xml
and
adding this to every fragment is working fine for me.
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}else{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
I am stuck with my issue.Thing is that its a custom Tab Widget.In that have multiple
tab like Home - News - Abc - PQR .
The Activity should be for both orientation like portrait and landscape. so for that each tab have two xml for portrait which is store at layout-port/file.xml and landscape which store at layout-land/file.xml
For manage orientation portrait to landscape i have added android:configChanges="orientation|keyboardHidden" rule tag in each activity.
TAB_SAMPLE.java Tab file.
TAB_GROUP_ACTIVITY each Tab Group activity File
file.java Task file
After all this stuff i get issue here :
If i addandroid:configChanges="orientation|keyboardHidden"rule tag in tab_sample activity then its working perfect. like manage different view. port to land and land to port but its not working in Home.java.
Now if i remove android:configChanges="orientation|keyboardHidden" rule tag in tab_sample activity then its working for Home activity not for News.java
Mean when i change the orientation its keeping same xml form port not use from layout-land.in the sense its call OnCreate() again.
So as i found may be issue is in Tab Widget.
Update
Now after tracing my code i get that main issue is in grid view activity because its only activity which is not working.
Issue is between Tab host v/s Grid View. I don't know why its not taking layout-land xml file. i found this as same issue but no replay on that question also
see in Detail manifestfile.xml
I want to maintain both portrait and landscape in all activity.
Both XML File
Please help me how to solve this.
Oooohhh Finally i got the solution for above issue. It's was very difficult.
For maintain the state of orientation Landscape to portrait and vice-versa we generally adding android:configChanges="keyboardHidden|orientation" property tag under activity.
But here may be issue is Tab_Group_ Activity due to that i am not able to maintain state in GridView. Grid_File.java is Only single java file which was not handling the orientation rest of all other working perfectly.
Now if i remove android:configChanges="keyboardHidden|orientation" from TAB_SAMPLE.java then Its handling only Grid_File.java not others.
mean that was keeping same Layout XML in landscape also where i have two separate XML File.
Here is my solution:
I have add android:configChanges="keyboardHidden|orientation" in TAB_SAMPLE.java as well as
implement onConfigurationChanged(Configuration newConfig) and set Number of column of grid. like gridView.setNumColumns(6);
#Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
// gridView.setSelection(index);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
// Log.e("On Config Change", "LANDSCAPE");
gridView.setNumColumns(6);
} else
{
// Log.e("On Config Change", "PORTRAIT");
gridView.setNumColumns(4);
}
}
Generally we are adding either android:configChanges="keyboardHidden|orientation" tag under activity or implementing onConfigurationChanged(Configuration newConfig) but here i have written both.
In my android application i designed two different layouts with same file name say my_profile.xml, and stored in two different directories i.e, 1) res/layout, 2) res/layout-land. Now the problem is if i start activity in Portrait mode it loads Portrait mode layout but after changing orientation it doesn't change layout, But if i start activity in Landscape mode it loads layout of landscape i.e, perfect. Problem is only when i change orientation, it doesn't handle it automatically. Can any one tell me, what can be the problem?
Check for the following :
1) In manifest file check for the below line in your activity
android:configChanges="orientation|keyboardHidden|screenSize"
2) Override the below function
#Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
Log.d(tag,"onconfig");
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
// do something
Log.d(tag,"land");
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
// do something
}
}
-Preeya
In your manifest.xml make the changes like this,,,,,
<activity android:name=".myActivity" android:windowSoftInputMode="adjustPan" android:configChanges="keyboardHidden"></activity>
dont use configuartionChanges="orientation"
Thats it...
Check your manifest file. If you have the following in your activity then REMOVE IT:
android:configChanges="keyboard|orientation|screenSize"
orientation causes the the activity to resort to the same layout rather than creating a new one.
I have the following problem: I have an image that I want to disappear when I change my phone from portrait to landscape. It works perfectly fine when I am on the current activity and I move orientations. It also works completely fine if I go to another activity and come back. But the problem is that after I return to my main page, onConfigurationChanged() will not be called the first time I change orientation. The image will show/not show correctly when I return, but when I first change the orientation after returning onConfigurationChanged() will not be called and the image will either stay/not stay until the second time I change the orientation. Any help you guys have would be extremely appreciated!
Here's a couple parts of my code. Ive put the configChange- orientation permission in the manifest already so thats not a problem.
#Override
public void onConfigurationChanged(Configuration newConfig) {L.p("configList",5200184);
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE&&isVertical==true) {
Logo.setVisibility(ImageView.GONE);
mainLogo.setVisibility(ImageView.GONE);
isHorizontal=true;
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT&&isHorizontal==true){
Logo.setVisibility(ImageView.VISIBLE);
mainLogo.setVisibility(ImageView.VISIBLE);
isVertical=true;
}
}
#Override
protected void onResume() {L.p("onResumeList", 5200113);
super.onResume();
Context ctx = getApplicationContext();
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
if((display.getOrientation() == Surface.ROTATION_90) || (display.getOrientation() == Surface.ROTATION_270))
{//Horizontal
L.p("you are resuming horizontal",5200124);
Logo.setVisibility(ImageView.INVISIBLE);
mainLogo.setVisibility(ImageView.INVISIBLE);
isHorizontal=true;
//isVertical=false;
}
else {//Vertical
L.p("you are resuming vertical",5200131);
Logo.setVisibility(ImageView.VISIBLE);
mainLogo.setVisibility(ImageView.VISIBLE);
isVertical=true;
// isHorizontal=false;
}
tracker.trackPageView("/deviceList");
}
Thanks!
No need to override orientation change. Just declare a new layout file in the layout-land folder that doesn't include the image (or in which the image is set to invisible/gone). When changing orientation, your activity will load that layout in onCreate.
Why do you check isHorizontal and isVertical?
Is it possible that one of those is false and that is causing it to fail the if conditional?
The onConfigurationChanged() method will not be called unless you declared the respective attributes under the <activity> in AndroidManifest.xml:
android:configChanges="orientation"
There is probably a flag somewhere causing the problem. And, we will probably never know what the problem is without seeing the full code, unfortunately.
But, please do not use configChange hacks. (https://plus.google.com/109306462100800920982/posts/LuYGURGdX7Q for a good explanation of the extremely rare case of when it is okay.)
Most likely, the onConfigurationChanged method does not need to be overridden at all here. Make a different layout for when the Activity is recreated on the configuration change.
My question is how to landscape Activity or TableLayout in the TabHost Layout?
I mean How to do something like this?
My Situation is the same this question
Android: Landscape Child Activity in a Portrait Tab Activity
Thanks,,,
As per my knowledge, all the layouts can automatically converts themselves in changed orientation mode. Please use below code to handle orientation mode.
Apply below code in menifest files for each activity for each tab.
android:configChanges="orientation|keyboardHidden"
Then apply below code to each code of each activity.
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE)
//Toast.makeText(getApplicationContext(), "no", Toast.LENGTH_SHORT).show();
{
}
else
{
}
}