繁体   English   中英

在Android应用程序的Gallery中选择图像:“ release()之后调用的方法”

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

我试图从我的android应用程序的Gallery中选择图像,但之后出现错误消息:

例外情况:

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

代码:

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);
        }
    }
    }

希望这能解决您的问题

在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;
    }

当我更改数字案例->案例1的案例2和案例2的案例1时,它就可以了!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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