{"id":2308,"date":"2022-08-30T15:23:47","date_gmt":"2022-08-30T15:23:47","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/05\/android-orientation-change-exits-app-but-w-o-crashing-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:23:47","modified_gmt":"2022-08-30T15:23:47","slug":"android-orientation-change-exits-app-but-w-o-crashing-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/android-orientation-change-exits-app-but-w-o-crashing-collection-of-common-programming-errors\/","title":{"rendered":"Android &#8211; Orientation Change &#8211; exits app but w\/o crashing-Collection of common programming errors"},"content":{"rendered":"<p>Looked at other posts but, haven&#8217;t seen the answer I&#8217;m looking for&#8230;<\/p>\n<p>I have two layouts: layout-port and layout-land.<br \/>\nIf I run the app with emulator or device, either vertically or horizontally, the app runs fine with the correct layouts.<\/p>\n<p><strong>However, if I rotate either the emulator or device, the app exits. There&#8217;s no crashing, perse&#8217;, it just exits.<\/strong><\/p>\n<p>I have other app&#8217;s with similarly defined layouts that work fine without any orientation handling in the manifest. I&#8217;m not concerned about persisting data.<\/p>\n<p><strong>The main differences<\/strong> between the one&#8217;s that work and this one are (this one has): * Menus with sub-menus * Dialog screens (not the android dialog widget)<\/p>\n<p>* Tab widget<\/p>\n<p>All of the above items work in their respective layouts (port and land), the app just exits when rotating the emulator or device and I need to restart the app.<\/p>\n<p>Any recommendations? Thanks <img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/60oPY.png\" \/><\/p>\n<p>The Manifest:<\/p>\n<p>(deleted)<\/p>\n<ol>\n<li>\n<p>If you use the above code, make one modification:<\/p>\n<pre><code>android:configChanges=\"keyboard|keyboardHidden|orientation\"\n<\/code><\/pre>\n<p>using only &#8220;orientation&#8221; will handle orientation changes driven by accelerometers and such, but on devices with a physical keyboard and a slide-out screen the activity will still be shut down and restarted any time a user slides open their keyboard.<\/p>\n<\/li>\n<li>\n<p>Did you try to add <code>android:configChanges=\"orientation\"<\/code> to your activity declaration in the manifest? Normally when the configuration changes, the activity is shut down and restarted. Adding this &#8220;flag&#8221; prevents this and calls the <code>onConfigurationChanged()<\/code> method instead.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-05 10:08:19. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Looked at other posts but, haven&#8217;t seen the answer I&#8217;m looking for&#8230; I have two layouts: layout-port and layout-land. If I run the app with emulator or device, either vertically or horizontally, the app runs fine with the correct layouts. However, if I rotate either the emulator or device, the app exits. There&#8217;s no crashing, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2308","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2308"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2308\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}