[英]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 : 我试图从我的android应用程序的Gallery中选择图像,但之后出现错误消息:
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 : 在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 !! 当我更改数字案例->案例1的案例2和案例2的案例1时,它就可以了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.