问题
I followed this tutorial to upload image to my server. But it closes my app once I click on one of the pictures in my gallery. I have two buttons one to browse and the other to upload once the user made their selection. To browse I do:
private void showFileChooser() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
And to get the results I override:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri filePath = data.getData();
try {
//Getting the Bitmap from Gallery
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
//Setting the Bitmap to ImageView
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
LogCat Error
01-06 17:32:02.937 24999-24999/? D/dalvikvm: Late-enabling CheckJNI
01-06 17:32:03.148 24999-24999/com.mypackage I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018_msm8226_LNX.LA.3.5.1_RB1__release_AU ()
OpenGL ES Shader Compiler Version: E031.24.00.08
Build Date: 03/07/14 Fri
Local Branch:
Remote Branch: quic/LNX.LA.3.5.1_RB1.1
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018 + f2fd134 + NOTHING
01-06 17:32:03.176 24999-24999/com.mypackage D/OpenGLRenderer: Enabling debug mode 0
01-06 17:32:21.603 24999-24999/com.mypackage W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
回答1:
I solved it. I had
android:noHistory="true"
on the same activity when I was doing login stuff and later on I changed my mind and wanted to change my architecture completely and forgot to delete that line or make it false; hence when I had the result from the gallery the activity was gone from the stack. Now I deleted it everything is like it's supposed to.
来源:https://stackoverflow.com/questions/34645792/android-volley-to-upload-image