Note that there are some explanatory texts on larger screens.

plurals
  1. POFragment flips and losses Image
    primarykey
    data
    text
    <p><strong>I've completely re-wrote the question to single down the scope.</strong></p> <p>I have Two Fragments that Flip around like a card(Left, Right). When the front fragment disappears flips it shows the back. Once the button is clicked again it flips to the front again but the ImageView on the front fragment is gone.</p> <p>I have tried different methods of saving the data of the Image picked.</p> <ol> <li>Saving the Fragment onSaveInstanceState</li> </ol> <p>This gives me a Null Pointer, so I figured I needed something more constant once being created.</p> <ol> <li>So now I save the image to SDCard once Picked</li> </ol> <p>This I figured would work and just check the path and grab it if its flipped to the front or the activity is recreated.</p> <p><strong>Here is some Code</strong></p> <p>onCreate():</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.new_postcard_activity); //UI call frontImageView = (ImageView) findViewById(R.id.imageView); Log.d(tag, "onCreate() Instance:" + savedInstanceState); //fragment start if (savedInstanceState == null) { Log.d(tag,"Instance Null"); getFragmentManager() .beginTransaction() .add(R.id.postcardFrame, new CardFrontFragment()) .commit(); if(!mShowingBack){ Log.d(tag,"Not showing back"); if(newPath != null &amp;&amp; newPath != ""){ Log.d(tag, "entered new path, not empty"); Drawable drawable = Drawable.createFromPath(newPath); Log.d(tag, "Should be setting saved image."); frontImageView.setImageDrawable(drawable); } } } else { mShowingBack = (getFragmentManager().getBackStackEntryCount() &gt; 0); Log.d(tag, "Instance is not Null"); } </code></pre> <p>Flip Button Click Listener</p> <pre><code>//flip card final Button cardBackButton = (Button) findViewById(R.id.cardBackButton); cardBackButton.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { flipCard(); }); </code></pre> <p>flipCard Method:</p> <pre><code>private void flipCard() { Log.d(tag2, "Log after flipCard:" + mShowingBack); if(mShowingBack) { //Flip to front flipFront(); return; } // Flip to back flipBack(); } </code></pre> <p>I set the Image onActivityResult from their PhotoGallery</p> <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_OK) { Uri photoUri = intent.getData(); if (photoUri != null) { try { ImageView setImage = (ImageView)findViewById(R.id.imageView); frontImage = MediaStore.Images.Media.getBitmap(this .getContentResolver(), photoUri); imageSet = true; //save image to SD if(imageSet == true){ Log.d(tag, "Inside Image Set if Statement"); String path = getExternalCacheDir() + "Postcards.png"; if(path != null &amp;&amp; path != ""){ Log.d(tag, "Path is:" + path); File file = new File(path); newPath = file.getAbsolutePath(); Log.d(tag, "New Path:" + newPath); if(file.exists()){ Log.d(tag, "File Exists"); Drawable d = Drawable.createFromPath(newPath); setImage.setImageDrawable(d); }else{ try{ Log.d(tag,"File didnt exist"); FileOutputStream out = new FileOutputStream(file); frontImage.compress(Bitmap.CompressFormat.PNG, 90, out); if(file.exists()){ Log.d(tag, "file exists now"); newPath = file.getAbsolutePath(); Drawable b = Drawable.createFromPath(newPath); setImage.setImageDrawable(b); } }catch(Exception e){ e.printStackTrace(); } } } } } catch (Exception e) { e.printStackTrace(); } </code></pre> <p>This is how I am accessing the image and trying to set it to my ImageView on Restart()</p> <pre><code>if(imageSet == true){ if(newPath != null &amp;&amp; newPath != ""){ ImageView view = (ImageView) findViewById(R.id.imageView); Drawable drawable = Drawable.createFromPath(newPath); view.setImageDrawable(drawable); } } </code></pre> <p>This seems like the best route in getting the image and setting it but it wont work. What would be best practice and how can I get it to perform the way I need it to?</p> <p>Much appreciated with any help!</p>
    singulars
    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.
 

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