Android save Activity data during screen rotation -


I do a lot of Google, but now I decided to ask ..

My activity only A simple thing - it downloads a photo from the Internet using Async Task.

But there are many problems, I'm not sure how to solve ..

1.] User will rotate the screen After Async Task has downloaded the picture Done .. How do I manage this screen rotation? Where to save temporarily to be available after the recurrence of the activity?

I want to lock the screen orientation (Android: Screen Orientation = "Landscape") or hand it on myself (

I know it's < Strong> onRetainNonConfigurationInstance ()

strong> and getLastNonConfigurationInstance () , but now both are excluded are bundled images I am not suitable for this because it is made for string (serialable) data. I can save it or file it somewhere, but it is unnecessary I've read somewhere, that this can be done by the loader, but I do not know how? Is it possible?

2 ] The user rotates the screen during , the ASC task is downloading an image.

I want to continue downloading AsyncTask. After the download completes, AsyncTask New to image in peat-acute method Brahmin) must save the activity.

I think that the internal class AsyncTask activity, then it works ..? But if I do not want to put it in the inner class then I have to save the context of the activity, for example in the variable but if I send the reference of the activity as a parameter of the constructor of Ancisketsk, and after the rotation on the screen the activity If reproduced, then the variable in the non-task Task mentions the original activity and hence the new one is not about the downloaded photo I know and have to start downloading it again ..

Or is AsyncTask bad for downloading images? Should I use something else? Service?

So .. how to solve these problems? I'm sure many app developers also have to solve it. But all this is Greek for me: (

When your asynchronous image has been downloaded, save it to your app's cache directory, place the saved image in a property on your activity class, then you override the onSaveInstanceState method. Your activities may be able to pass the cached image path during an orientation change. Check the savedInstanceState bundle for a saved image path in your onCreate method. If that path exists, try downloading the image again. Instead, simply load the image from the disk.

Comments