我需要使用onActivityResult选择一个图像,但onActivityResult不要等待用户提取。
我尝试了一些不同的样本,没有任何改变。
这里onActivityResult:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
Log.i("onActivityResult", "onActivityResult started!");
if (requestCode == 1 && resultCode == RESULT_OK && null != data)
{
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Log.i("onActivityResult", "onActivityResult");
//ImageView imageView = (ImageView) findViewById(R.id.imgView);
//imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
这就是我打电话的方式:
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if (id == R.id.action_settings)
{
//something
return true;
}
else if (id == R.id.cikis)
{
//something
return true;
}
else if ( id == R.id.background)
{
Log.i("background", "clicked to background!");
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
MainActivity.this.startActivityForResult(i, RESULT_LOAD_IMAGE);
return true;
}
return super.onOptionsItemSelected(item);
}
我不明白为什么。我坚持在这里。
解决!
我删除了清单中的 android:launchMode =" singleInstance" (内部标记)行,而不是它的正常工作!