0

New to Android development here.I'm currently making an app in which when the Orientation changes . I want the message in my LogCat .For this I have made onConfigurationChanged(Configuration newConfig) method in the MainActivity, but it is not called when running the program.

Basically, I want to cease my Activity from restarting upon a device orientation change. To do this, I have modified the activity in the manifest file: I used

android:configChanges="orientation|screenSize"  
android:minSdkVersion="8"
android:targetSdkVersion="17" 

ON LogCat I'm getting text as follows:

Emulator without GPU emulation detected.

The application may be doing too much work on its main thread.

I already found a solution through Google in which above targetSdkVersion "17" we use--

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|layoutDirection"

It is also not working.

Can anyone help me out?

This is my MainActivity:

       package com.example.orientation;
        import android.app.Activity;
        import android.content.res.Configuration;
        import android.os.Bundle;
        import android.util.Log;
        import android.view.Menu;
        import android.view.MenuItem;
           public class MainActivity extends Activity {
           protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.activity_main);

            }


           public void onConfigurationChanged(Configuration newConfig) {

            super.onConfigurationChanged(newConfig);
             Configuration c = getResources().getConfiguration();

                Log.e("Config",""+c);
             if (c.orientation == Configuration.ORIENTATION_PORTRAIT) 
               {
                    // portrait

                   Log.e("On Config Change","portrait");

                  } 
                else if (c.orientation == Configuration.ORIENTATION_LANDSCAPE) 
                 {
                    // landscape
                    Log.e("On Config Change","LANDSCAPE");

                  }

               }

             }

However, the Program is running when the orientation changes, but the onConfigurationChanged() method is not being called.

Does anyone know why this may be happening?

Simas
  • 43,548
  • 10
  • 88
  • 116
  • Can you add a Log.e() statement as the first line in `onConfigurationChanged()` to confirm that the thread does not enter at all. Also try adding an `@Override` line for `onConfigurationChanged()` to ensure the signature of `onConfigurationChanged()` is correct. Your IDE editor will show an error if something's wrong in the signature. – faizal Jul 06 '14 at 09:31
  • Are you using `setRequestedOrientation()`? See http://stackoverflow.com/a/6109206/2105986. – faizal Jul 06 '14 at 10:16

1 Answers1

0

The very same code works for me.

This is what my activity tag looks like in the manifest :

    <activity
        android:name="com.example.tempproject.MainActivity"
        android:configChanges="screenSize|keyboardHidden|orientation"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
Shivam Verma
  • 7,973
  • 3
  • 26
  • 34