What is the correct way to refresh UI when I use android:configChanges="keyboardHidden|orientation"

by MrSnowflake » Fri, 24 Apr 2009 21:01:27 GMT


Sponsored Links
 Why do so much people avoid the destoying and recreation of Activities
on orientation change. It's there to make the switch to a different
orientation easier, because it automatically loads the correct
resources. To be honest, I don't fully understand the whole recreation
of Activities neither, as it would take a lot of time to recreate the
activity and loading (and saving the instance state too) the instance
state could take a long time too. But I bet those intelligent Google
people have good reasons, that's why I follow their idea.

I don't know how to refresh your UI. If you mean by refreshing:
loading the appropriate resources to get the correct layout for the
current orientation, then you need to destroy and recreate the
Activity. That's why the system does this by default!

You should save all current state specific information in
onSaveInstancestate() (or what is it called, I forgot, it's a couple
of weeks ago I did some Androiding :) ) and reload it in
onRestoreInstancestate(). And well, all this stuff is in the docs so
you can take a look there :).



--~--~---------~--~----~------------~-------~--~----~



What is the correct way to refresh UI when I use android:configChanges="keyboardHidden|orientation"

by Wang He » Mon, 27 Apr 2009 10:56:20 GMT


 Is here anybody knows the right way?
Still waiting ...

BRs
He



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


What is the correct way to refresh UI when I use android:configChanges="keyboardHidden|orientation"

by Wang He » Mon, 27 Apr 2009 16:26:10 GMT


 1. I don't want to  recreate the activity when switching at Land &
Port, many runtime data I don't want to save and reload;
2. So I use onConfigurationChanged() facility, but I have UI for Land
& Port, What I do now is:
    public void onConfigurationChanged(Configuration newConfig) {
           setContentView() again as onCreate();
          run findViewById()s as handlers will lost after
setContentView();
          setListeners for UI widgets as they will lost also;
  }

3. Is the way right I did in 2?

BRs
He





--~--~---------~--~----~------------~-------~--~----~



What is the correct way to refresh UI when I use android:configChanges="keyboardHidden|orientation"

by MrSnowflake » Mon, 27 Apr 2009 19:52:06 GMT


 You don't have to load and save that stuff, you can put references to
your runtime data in a custom class and return that in
Activity.onRetainNonConfigurationInstance()  (http://
developer.android.com/reference/android/app/
Activity.html#onRetainNonConfigurationInstance()) and get it in
Activity.getLastNonConfigurationInstance().






--~--~---------~--~----~------------~-------~--~----~



What is the correct way to refresh UI when I use android:configChanges="keyboardHidden|orientation"

by quakeboy » Tue, 28 Apr 2009 17:17:00 GMT


 You might want to take a look at setRequestedOrientation if u want
to ..



--~--~---------~--~----~------------~-------~--~----~