[英]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.