简体   繁体   中英

Pick image from Gallery in android app : “Method called after release() ”

i tried to to pick image from Gallery in my android application but after that an error message appears :

Exception :

java.lang.RuntimeException: Method called after release()

Code :

public class ProductAfter extends Fragment{
......

    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);

            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, 1);

......
}
First Step :

You have to @Override this method to catch the call back from the Gallery to Fragment

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    // Check with your Request code and do stuff with that 
}

Second Step:

 From the Gallery the call back will be directly to the Parent Activity, So you have to  @Override  the same method in the parent Activity 

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


   // here check for all the fragments where the method is overidden and callback reaches there 
        for (Fragment fragment : getSupportFragmentManager().getFragments()) {
            if (fragment != null)
                fragment.onActivityResult(requestCode, resultCode, data);
        }
    }
    }

Hope this will resolve you issues

in TabsPagerAdapter :

 @Override
    public Fragment getItem(int index) {


        switch (index) {

        case 0:
            // Games fragment activity
            return new CategorieFragment();
        case 1:
            // Movies fragment activity
            return new ProductBefore();         
        case 2:

            return new ProductAfter();

        case 3:
            // Top Rated fragment activity
            return new CodeBarreAuto();



        }

        return null;
    }

when i change number cases --> case 2 by case 1 and case 1 by case 2 it's woks fine !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM