views:

83

answers:

3

I have i Gallerywiew Im using lazyload to download images but when i rotate device its reload all images and not use the cache.

if i do android:configChanges="keyboardHidden|orientation"

the current images are in size of latest orientation.

to get the images to show full size i do

Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight();

hope you understan

A: 

When you rotate the screen, you go through the activity lifecycle. The activity goes through onDestroy() and its onCreate() method gets called. You must redo any display calculations and view changes in onCreate and use the savedInstanceState to persist app data.

I hope this is what you were asking

Falmarri
A: 

You need to override your onGonfigurationChanged event.

In my app I was playing music and when you flipped the phone it would stop and then I found out that if I overrode the config change I could just tell it to start my timer again and nothing was lost. I know this inst exactly what you wanted but it may help get you going in the right direction.

 @Override
             public void onConfigurationChanged(Configuration newConfig) {
               super.onConfigurationChanged(newConfig);
              startTimer();

             }
dweebsonduty
+2  A: 

Overriding onConfigurationChanged() is discouraged because there's so much work you have to do to get it right.

What you want to do is implement onRetainNonConfigurationInstance() in your activity. This is called just before your activity is killed when the system knows it will be restarting it in a moment (e.g. for screen rotation).

Your implementation of onRetainNonConfigurationInstance() may return any object it likes ('this' is a good choice, or in your case, your cache). This object will be held and made available to the next invocation of your activity.

In your onCreate() method, call getLastNonConfigurationInstance() to retrieve the object the system is saving for you. If this function returns null, proceed as you would normally. If it returns non-null, then that will be the object you previously passed back from onRetainNonConfigurationInstance() and you can extract any information you want from it. This generally means that you don't need anything from the savedInstanceState bundle or from saved preferences.

I believe even open sockets, running threads, and other objects can be preserved across configuration changes this way.

Edward Falk
Thanks! this is what im looking for!
FoJjen