I need to pick an image with onActivityResult, but onActivityResult not wait to user for pick up.
I tried some different samples, nothing changed.
Here 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));
}
And here how i call :
@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);
}
I don't understand why. Im stuck on here.
SOLVED!
I delete to android:launchMode="singleInstance" (inside tag ) line in manifest, than it's work correctly!