Question

I have an application, part of which is a fragment in which the camera takes a pic, when the picture is taken another fragment is loaded to display the image. The user then has the choice to retake the pic if not happy. This should go back to the previous fragment (camera) and it does as the overlay is displayed, however the image previously taken is still displayed.

EDIT** I debugged through it and when the image is taken and the next fragment is loaded, the onpause() isn't called, so, when the user clicks retake, the onresume isnt called which reinstantiates my camera. I know there have been similar questions here but I can't seem to find the answer to my problem.**EDIT

It should be said that I am integrating with someone elses work here and that is causing confusion. Here are the two methods for going to next fragment and going to previous fragment

NEXT

public void gotoNextFragment(String nextTag, Fragment nextFragment){

    FragmentManager  fm = getSupportFragmentManager();

    FragmentTransaction ft = fm.beginTransaction();
    ft.setCustomAnimations(R.animator.enter_slide_in, R.animator.enter_slide_out);

    boolean newlyCreated = false;
    if(nextFragment == null){
        nextFragment = Fragment.instantiate(this, nextTag);
        newlyCreated = true;
    }

    //hide current fragment
    ft.hide(fm.findFragmentByTag(Misc.currentContentFragmentTag));

    if(newlyCreated){
        ft.add(R.id.content_frame, nextFragment, nextTag);
    }
    else{
        ft.show(nextFragment);
    }
    ft.addToBackStack(null);
    ft.commit();
    Misc.currentContentFragmentTag = nextTag;

}

PREVIOUS

public void gobackToPreviousFragment(String preFragmentTag,Fragment f){

    FragmentManager  fm = getSupportFragmentManager();

    FragmentTransaction ft = fm.beginTransaction();
    ft.setCustomAnimations(R.animator.close_slide_in,R.animator.close_slide_out);

    ft.show(f);
    ft.remove(fm.findFragmentByTag(Misc.currentContentFragmentTag));                    
    ft.addToBackStack(null);
    ft.commit();

    Misc.currentContentFragmentTag = preFragmentTag;

}

If anyone would have any insight as to what I need to do to ensure onResume() is called I'd appreciate it...

EDIT The image preview that is still displayed is that of the standard camera image preview, not from the fragment for previewing

Was it helpful?

Solution

When you hide() show() fragments you don't get a call to onResume(). Then you only get a call the first time the fragment is created.

OTHER TIPS

the onResume()-method is always called before the fragment is running. check the lifecycle-diagram --> http://docs.xamarin.com/static/guides/android/platform_features/fragments/part_1_-_creating_a_fragment/Images/fragment_lifecycle.png

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top