Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing Extras and screen rotation
    primarykey
    data
    text
    <p>This kind of questions appear periodically. Sorry if this has been covered before, but I'm a newbie and couldn't find the appropriate answer. It deals with the correct implementation of communication between classes and activities.</p> <p>I made a gallery app. It has 3 main activities: the <code>Main</code> one, to search for filenames using a pattern; a <code>Thumb</code> one, that shows all the images that matched the pattern as thumbnails in a gridview, and a <code>Photo</code> activity, that opens a full sized image when you click a thumb in <code>Thumbs</code>. I pass to the <code>Photo</code> activity via an <code>Intent</code> the filenames (an array), and the <code>position</code> (an <code>int</code>) of the clicked thumb in the gridview.</p> <p>This third <code>Photo</code> activity has only one view on it: a <code>TouchImageView</code>, that I adapted for previous/next switching and zooming according to where you shortclick on the image (left, right or middle). Moreover, I added a longclick listener to <code>Photo</code> to show EXIF info. </p> <p>The thing is working, but I am not happy with the implementation... Some things are not right.</p> <p>One of the problems I am experiencing is that, if I click on the right of the image to see the next in the <code>Photo</code> activity, it switches fine (<code>position++</code>), but when rotating the device the original one at <code>position</code> appears.</p> <p>What is happening is that <code>Photo</code> is destroyed when rotating the image, and for some reason it restarts again, without obeying <code>super.onCreate(savedInstanceState)</code>, loading again the Extras (the <code>position</code> only changed in <code>Photo</code>, not on the parent activities).</p> <p>I tried with <code>startActivityForResult</code> instead of <code>startActivity</code>, but failed...</p> <p>Of course I can do something contrived to save the <code>position</code> data, but there should be something "conceptual" that I am not understanding about how activities work, and I want to do this right.</p> <p>Can someone please explain me what I am doing wrong, which is the best method to implement what I want, and why?</p> <p>Thanks a lot!!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload