在我的片段中,我已经开始了用于照片捕获的 startActivityforresult 意图。我已经覆盖了片段类中的 onActivityResult 回调方法。我已经在主要活动中为其他一些意图实现了 onActivityResult 回调。我的问题是执行调用活动 onActivityResult 方法并返回空指针异常后的片段 onActivityResult。Fragment onactivityresult 方法
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK)
{
prof_bitmap = null;
if (requestCode == 0)
{
Log.e("" ,"entered activity Result Code 0");
Uri photoUri = data.getData();
if (photoUri != null)
{
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getActivity().getContentResolver().query(
photoUri, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Log.e("" ,"File Path" +filePath);
prof_bitmap = setImage(filePath);
}
}
if (requestCode == 1)
{
Log.e("" ,"entered activity Result Code 1");
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
prof_bitmap = bitmap;
Log.e("" ,"entered activity Result Code 1"+bitmap);
profile_pic.setImageBitmap(bitmap);
}
}
}
活动 onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
Log.e("" ,"called onActivityResult in main");
Session.getActiveSession().onActivityResult(this, requestCode,
resultCode, data);
}
如何仅调用片段 onactivityresult 方法?
我的日志猫
将结果 ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data dat=content://media/external/images/media/222 (has extras) }} 传递给活动失败{com.mobiotics.tvbuddydemo/com.mobiotics.tvbuddydemo.TVBuddyMainActivity}:java.lang.NullPointerException