Reputation: 39810
As far as I know, by default, when device is rotated, the current activity is destroyed and recreated. I'm rotating the emulator using LeftCTRL+F12 but it's not destroyed. I have logs in OnDestroy
, OnCreate
and OnStart
and OnResume
, but none of those fire up when I rotate the device.
Before:
After:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.geo_quiz"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.geo_quiz.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Upvotes: 4
Views: 1557
Reputation: 41
Your emulated device, i.e., the phone, (not the emulator) may not have rotation detection turned on. In the phone's settings, turn on rotation detection. Here is a screenshot of what that icon looks like.
Upvotes: 3
Reputation: 336
I think I know the answer. I have the same problem using the emulator for Pixel 2, API level 28, on Android Studio 3.4.1 (the latest as of writing this).
How I fixed this was by dragging the Quick Settings drop-down menu on the emulator (click and drag from the top right corner of the emulator's screen), and ensuring that auto-rotation was enabled.
When I checked, it wasn't, so I enabled it. After enabling it, the emulator worked normally :).
Hope this helped!
Upvotes: 8
Reputation: 351
Go to the camera app first, then run your application. The camera app automatically changes your view.
Upvotes: 0
Reputation: 12512
Based on your screen shots, it seems that the device was not changing orientation. Your activity still shows a portrait layout. THe only thing that changed is the orientation of the displayed window. When an orientation change happen, your text should be upright, in the screenshot their "up" points to the left. Run it on a real device, and onDestroy will be called. 100% of the time. guaranteed
Edit following Oleksiy comments:
try numpad7 first and then CMD+f12.
Also make sure your ADT is up to date (not just your build tools) - you do that by Eclipse > Check for Updates.
If the above does not work, try to do this programmatically, so you can debug your code (which will work on a real device): call setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
in your onCreate
You shouldn't be doing development with emulator. Its too slow and unreliable. Bunch of stuff won't work there. Work with your device connected. you'll save yourself trouble.
I also found this bugreport, which was tagged "unreproducable": http://code.google.com/p/android/issues/detail?id=17963
Upvotes: 0