Reputation: 512
Just making a test application that should display a log message on changing orientation, but when i change orientation using ctrl + f11, there is nothing shown in the logcat. what is the issue in the coding
A Part From Manifest
<activity
android:name="com.example.orientationtest.MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize" >
A part from Java
package com.example.orientationtest;
import android.os.Bundle;
import android.app.Activity;
import android.content.res.Configuration;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
Log.d("error", " orientation changes");
}
}
Upvotes: 1
Views: 70
Reputation: 17976
Using configChanges
is not a good idea if you only want to know if the screen rotated. It basically means that you plan to handle the whole rotation change by yourself in the code.
If you don't plan to do this, just check what is the current rotation when your Activity
is created:
int currentOrientation = getResources().getConfiguration().orientation;
Then just do whatever you want using this check:
if(currentOrientation == Configuration.ORIENTATION_LANDSCAPE){
//if landscape
} else {
//if portrait
}
This way you don't need to touch your manifest file and you let your app manage the configuration changes by itself.
You can keep the previous orientation used in the activity saved instance if you need to compare the previous and the current one.
Upvotes: 1
Reputation: 549
try this if target api 13 and above
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
or
android:configChanges="orientation|keyboardHidden|screenLayout"
for lower than 13 ..... this will help you... :)
Upvotes: 4
Reputation: 26198
The issue is that you prevented the android from changing its orientation
android:configChanges="orientation|screenSize"
that line of code is preventing it to configuration change and that why your not getting any response..
Upvotes: 0