{"id":3811,"date":"2014-03-30T05:49:55","date_gmt":"2014-03-30T05:49:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/android-application-showing-overlay-items-in-asynctask-collection-of-common-programming-errors\/"},"modified":"2014-03-30T05:49:55","modified_gmt":"2014-03-30T05:49:55","slug":"android-application-showing-overlay-items-in-asynctask-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/android-application-showing-overlay-items-in-asynctask-collection-of-common-programming-errors\/","title":{"rendered":"Android application: showing overlay items in AsyncTask-Collection of common programming errors"},"content":{"rendered":"<p>As said by the other answers you can solve your problem using onSaveInstanceState(Bundle outstate) and onRestoreInstanceState(Bundle savedInstanceState) or even disabling orientation changes in the device.<\/p>\n<p>Lets see one by one:<\/p>\n<p>-Disabling orientation changes, may result in a pour user experience, so I would not favour it.<\/p>\n<p>-Using onSaveInstanceState(Bundle outstate) and onRestoreInstanceState(Bundle savedInstanceState) you have two main oprions &#8230;<\/p>\n<p>Option 1:<\/p>\n<p>You can save only basic information about items being displayed (i.e. if it&#8217;s a map, you could save map center location and zoom) and then retrieve again from the database all the overlays information. That&#8217;s very simple but it may bacome very slow if you have several hundred of overlay items to retrieve, resulting again in a pour user experience.<\/p>\n<p>Option 2:<\/p>\n<p>You could use parcelable to extend you overlay Item so you could save all the overlay items during onSaveInstanceState(Bundle outstate), and restore them without reloading from database. I&#8217;ve used this for with several thousand of items, and it works quite well.<\/p>\n<p>You can find parcelable information in here: Google and and example in here: Android &#8211; Parcel data to pass between Activities using Parcelable classes<\/p>\n<p>Good luck<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As said by the other answers you can solve your problem using onSaveInstanceState(Bundle outstate) and onRestoreInstanceState(Bundle savedInstanceState) or even disabling orientation changes in the device. Lets see one by one: -Disabling orientation changes, may result in a pour user experience, so I would not favour it. -Using onSaveInstanceState(Bundle outstate) and onRestoreInstanceState(Bundle savedInstanceState) you have two [&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-3811","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3811","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=3811"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3811\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}