How to reuse layout set in setContentView? Android -


i trying use android:configchanges="keyboardhidden|orientation|screensize" in manifest cannot lose state of videoview when configuration changes happen. means need choose layouts myself on configuration. problem having when first initialize view use in oncreate, here:

 @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          if (getresources().getconfiguration().orientation ==                 configuration.orientation_landscape) {             setcontentview(r.layout.activity_make_photo_video_land);          } else if (getresources().getconfiguration().orientation ==                 configuration.orientation_portrait) {             setcontentview(r.layout.activity_make_photo_video);         } } 

it chooses right layout. when need adjust layout on configuration change here:

@override     public void onconfigurationchanged(configuration newconfig) {         super.onconfigurationchanged(newconfig);          if (getresources().getconfiguration().orientation ==                 configuration.orientation_landscape) {             setcontentview(r.layout.activity_make_photo_video_land);         } else if (getresources().getconfiguration().orientation ==                 configuration.orientation_portrait) {             setcontentview(r.layout.activity_make_photo_video);         }       } 

it not use same instance of layout, rather reloads it, makes videoview go black. unable press buttons after that.

is there way reuse initial layouts? have tried set views 1 setcontentview(r.layout.activity_make_photo_video_land); activity activity object, ide won't let me, says activity incompatible void. because if reference view, reuse it. or there simpler way of doing not seeing?

thanks.

enter image description here

i suggesting alternative , simple solution problem :

1. move layout activity_make_photo_video_land /res/layout-land/ folder , rename activity_make_photo_video.xml

this way activity_make_photo_video_land view (rename activity_make_photo_video) inflated when orientation changes landscape

so, not required handle these facility manually java code.

change oncreate() :

 @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);              setcontentview(r.layout.activity_make_photo_video_land);  } 

your application have single layout activity_make_photo_video in /res/layout/ , /res/layout-land/ both folder

update :

unless specify otherwise, configuration change (such change in screen orientation, language, input devices, etc) cause current activity destroyed, going through normal activity lifecycle process of onpause(), onstop(), , ondestroy() appropriate. if activity had been in foreground or visible user, once ondestroy() called in instance new instance of activity created, whatever savedinstancestate previous instance had generated onsaveinstancestate(bundle).

override onsaveinstancestate(bundle) , save state here

you can check more here

i hope work


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -