1 year ago
#100061
Luis A. Florit
Problem when switching between landscape and portrait layouts
I have an app with an activity called OpenBird
with two layouts, one in res/layout (for portrait), the other in res/layout-land (for landscape). In the manifest I also have android:screenOrientation="fullSensor"
since I want to allow 180 degree rotations.
Yet, when I turn the device 90 degrees, the activity is destroyed (yet I can see the device trying to switch the layout). If I add android:configChanges="orientation"
in the manifest the activity is not destroyed, but the layout does not change accordingly.
I tried to follow this without success. I should be doing something stupid that I cannot see...
This is the logcat in Android studio when I switch orientations:
...myapp I/ViewRootImpl@85d8dd0[OpenBird]: stopped(true) old=false
...myapp I/SurfaceControl: nativeRelease nativeObject s[489369727840]
...myapp I/SurfaceControl: nativeRelease nativeObject e[489369727840]
...myapp W/libEGL: EGLNativeWindowType 0x71f1bb9010 disconnect failed
...myapp I/ViewRootImpl@85d8dd0[OpenBird]: dispatchDetachedFromWindow
...myapp I/DecorView: [INFO] isPopOver=false, config=true
...myapp I/DecorView: updateCaptionType >> DecorView@5c43430[], isFloating=false, isApplication=true, hasWindowDecorCaption=false, hasWindowControllerCallback=true
...myapp W/MediaPlayerNative: info/warning (10973, 0)
...myapp I/ViewRootImpl@58124a2[OpenBird]: setView = com.android.internal.policy.DecorView@5c43430 TM=true
...myapp I/SurfaceControl: nativeRelease nativeObject s[489958791712]
...myapp I/SurfaceControl: nativeRelease nativeObject e[489958791712]
...myapp I/SurfaceControl: nativeRelease nativeObject s[489958791616]
...myapp I/SurfaceControl: nativeRelease nativeObject e[489958791616]
...myapp I/SurfaceControl: nativeRelease nativeObject s[489958791520]
...myapp I/SurfaceControl: nativeRelease nativeObject e[489958791520]
...myapp I/SurfaceControl: assignNativeObject: nativeObject = 0 Surface(name=null)/@0xcf0e8ee / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1820 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
...myapp I/ViewRootImpl@58124a2[OpenBird]: Relayout returned: old=(0,0,1080,2400) new=(0,0,1080,2400) req=(1080,2400)0 dur=7 res=0x7 s={true 489955397632} ch=true fn=-1
...myapp I/ViewRootImpl@58124a2[OpenBird]: [DP] dp(1) 1 android.view.ViewRootImpl.reportNextDraw:10957 android.view.ViewRootImpl.performTraversals:3845 android.view.ViewRootImpl.doTraversal:2618
...myapp I/ViewRootImpl@58124a2[OpenBird]: [DP] pd() Asnyc report
...myapp I/ViewRootImpl@58124a2[OpenBird]: [DP] pdf(0) 1 android.view.ViewRootImpl.lambda$performDraw$1$ViewRootImpl:4668 android.view.-$$Lambda$ViewRootImpl$DJd0VUYJgsebcnSohO6h8zc_ONI.run:6 android.os.Handler.handleCallback:938
...myapp I/ViewRootImpl@58124a2[OpenBird]: [DP] rdf()
...myapp I/SurfaceControl: nativeRelease nativeObject s[491413945504]
...myapp I/SurfaceControl: nativeRelease nativeObject e[491413945504]
...myapp I/SurfaceControl: nativeRelease nativeObject s[489958791712]
...myapp I/SurfaceControl: nativeRelease nativeObject e[489958791712]
...myapp I/DecorView: [INFO] isPopOver=false, config=true
...myapp I/DecorView: updateCaptionType >> DecorView@d151cbc[AveActivity], isFloating=false, isApplication=true, hasWindowDecorCaption=false, hasWindowControllerCallback=true
...myapp I/ViewRootImpl@85e7638[AveActivity]: stopped(false) old=true
...myapp I/ViewRootImpl@85e7638[AveActivity]: stopped(false) old=false
...myapp I/SurfaceControl: assignNativeObject: nativeObject = 0 Surface(name=null)/@0x389ce5a / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1820 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
...myapp I/ViewRootImpl@85e7638[AveActivity]: Relayout returned: old=(85,0,2400,1080) new=(0,0,1080,2400) req=(2315,1080)0 dur=7 res=0x7 s={true 489955405824} ch=true fn=-1
...myapp I/ViewRootImpl@85e7638[AveActivity]: [DP] dp(1) 1 android.view.ViewRootImpl.reportNextDraw:10957 android.view.ViewRootImpl.performTraversals:3845 android.view.ViewRootImpl.doTraversal:2618
...myapp I/ViewRootImpl@85e7638[AveActivity]: [DP] pd() Asnyc report
...myapp I/ViewRootImpl@85e7638[AveActivity]: [DP] pdf(0) 1 android.view.ViewRootImpl.lambda$performDraw$1$ViewRootImpl:4668 android.view.-$$Lambda$ViewRootImpl$DJd0VUYJgsebcnSohO6h8zc_ONI.run:6 android.os.Handler.handleCallback:938
...myapp I/ViewRootImpl@85e7638[AveActivity]: [DP] rdf()
...myapp I/SurfaceControl: nativeRelease nativeObject s[489958797472]
...myapp I/SurfaceControl: nativeRelease nativeObject e[489958797472]
...myapp I/SurfaceControl: nativeRelease nativeObject s[489958797376]
...myapp I/SurfaceControl: nativeRelease nativeObject e[489958797376]
...myapp I/ViewRootImpl@85e7638[AveActivity]: MSG_RESIZED_REPORT: frame=(0,0,1080,2400) ci=(0,85,0,126) vi=(0,85,0,126) or=1
...myapp I/ViewRootImpl@85e7638[AveActivity]: [DP] dp(1) 1 android.view.ViewRootImpl.reportNextDraw:10957 android.view.ViewRootImpl.access$1200:256 android.view.ViewRootImpl$ViewRootHandler.handleMessage:6101
...myapp I/SurfaceControl: nativeRelease nativeObject s[489958791712]
...myapp I/SurfaceControl: nativeRelease nativeObject e[489958791712]
...myapp I/SurfaceControl: assignNativeObject: nativeObject = 0 Surface(name=null)/@0x389ce5a / android.view.SurfaceControl.readFromParcel:1117 android.view.IWindowSession$Stub$Proxy.relayout:1820 android.view.ViewRootImpl.relayoutWindow:9005 android.view.ViewRootImpl.performTraversals:3360 android.view.ViewRootImpl.doTraversal:2618 android.view.ViewRootImpl$TraversalRunnable.run:9971 android.view.Choreographer$CallbackRecord.run:1010 android.view.Choreographer.doCallbacks:809 android.view.Choreographer.doFrame:744 android.view.Choreographer$FrameDisplayEventReceiver.run:995
...myapp I/SurfaceControl: nativeRelease nativeObject s[489958794688]
...myapp I/SurfaceControl: nativeRelease nativeObject e[489958794688]
...myapp I/SurfaceControl: nativeRelease nativeObject s[491543273760]
...myapp I/SurfaceControl: nativeRelease nativeObject e[491543273760]
...myapp I/ViewRootImpl@85e7638[AveActivity]: Relayout returned: old=(0,0,1080,2400) new=(0,0,1080,2400) req=(1080,2400)0 dur=7 res=0x1 s={true 489955405824} ch=false fn=3
...myapp I/ViewRootImpl@85e7638[AveActivity]: [DP] pd() Asnyc report
...myapp W/libEGL: EGLNativeWindowType 0x72139e3010 disconnect failed
...myapp I/ViewRootImpl@85e7638[AveActivity]: [DP] pdf(0) 1 android.view.ViewRootImpl.lambda$performDraw$1$ViewRootImpl:4668 android.view.-$$Lambda$ViewRootImpl$DJd0VUYJgsebcnSohO6h8zc_ONI.run:6 android.os.Handler.handleCallback:938
...myapp I/ViewRootImpl@85e7638[AveActivity]: [DP] rdf()
...myapp I/ViewRootImpl@58124a2[OpenBird]: stopped(true) old=false
...myapp I/SurfaceControl: nativeRelease nativeObject s[489958791616]
...myapp I/SurfaceControl: nativeRelease nativeObject e[489958791616]
...myapp W/libEGL: EGLNativeWindowType 0x72139e1010 disconnect failed
...myapp I/ViewRootImpl@58124a2[OpenBird]: dispatchDetachedFromWindow
...myapp I/ViewRootImpl@85e7638[AveActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
...myapp I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
...myapp I/SurfaceControl: nativeRelease nativeObject s[489958797472]
...myapp I/SurfaceControl: nativeRelease nativeObject e[489958797472]
...myapp I/SurfaceControl: nativeRelease nativeObject s[489958791712]
...myapp I/SurfaceControl: nativeRelease nativeObject e[489958791712]
EDIT A few extracts from the activity code that may be useful (it is too big, sorry).
OpenBird.java:
...
public class OpenBird extends Activity implements
Downloads.OnSongsDownloaded,
Downloads.OnMapsDownloaded,
Downloads.OnThumbsDownloaded,
Downloads.OnInfoDownloaded {
...
private class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null) {
if ("OpenBird-stop".equals(action)) {
stop();
}
}
}
}
...
@Override
public void onPause() {
super.onPause();
synchronized (this) {
boolean screenon;
if (Build.VERSION.SDK_INT >= 20)
screenon = powerManager.isInteractive();
else
screenon = powerManager.isScreenOn();
if (!screenon && MyMusicService != null && MyMusicService.isPlaying()) {
ScreenOffMS = System.currentTimeMillis();
stop();
} else
ScreenOffMS = 0;
mHandler.removeCallbacks(mHandlerTask);
}
}
@Override
public void onResume() {
super.onResume();
synchronized(this){
// Solo volver a tocar si se pasaron menos de 90 segundos (90000ms), para no joder gravacion de otros
if (MyMusicService != null) {
if (! MyMusicService.isPlaying() && System.currentTimeMillis() < ScreenOffMS + 90000)
play();
if (MyMusicService.isPlaying())
runOnUiThread(mHandlerTask);
}
}
}
@Override
public void onDestroy() {
super.onDestroy();
refwiki = null;
ppnamewiki = null;
stop();
setVolume();
setResult(result);
try {
unregisterReceiver(myBroadcastReceiver);
} catch (Exception e) {
// already unregistered
}
mHandler.removeCallbacksAndMessages(null);
finish();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getApplicationContext();
if (AveActivity.fs) setTheme(R.style.MyTheme);
setContentView(R.layout.birdview);
...
myBroadcastReceiver = new MyBroadcastReceiver();
registerReceiver(myBroadcastReceiver, new IntentFilter("OpenBird-stop"));
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.floritfoto.apps.ave"
xmlns:tools="http://schemas.android.com/tools"
android:versionCode="272"
android:versionName="3.11.5">
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
tools:ignore="AllowBackup"
tools:replace="android:label, android:name"
android:allowBackup="true"
android:requestLegacyExternalStorage="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name_home"
android:theme="@style/MyThemeNonFS"
android:launchMode="singleTask"
android:name="com.floritfoto.apps.ave.AveSetExtCache"
android:usesCleartextTraffic="true"
tools:targetApi="m">
<service
android:name=".MusicService"
android:enabled="true" />
<service
android:name=".GPSService"
android:enabled="true" />
<activity
android:name=".AveActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="OpenBird">
</activity>
<!-- Libraries -->
<activity android:name="com.floritfoto.apps.xvf.Foto" />
<activity android:name="com.floritfoto.apps.xvf.FileChooser" />
<activity android:name="com.floritfoto.apps.xvf.Thumbs" />
</application>
</manifest>
android
android-layout
android-orientation
0 Answers
Your Answer