谢谢你的时间。我正在做一个应用程序,我从中启动图库,活动 A 选择一个图像并返回到同一个活动 A。
我从具有单个活动(在清单上定义为启动器)的项目中没有问题,但是当我从清单上默认定义的活动的整个项目中执行此操作时,它无法正常工作。
我用来打开图库并选择照片的意图:
public void openGallery(int req_code){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select file to upload "), req_code);
}
我获取数据的 onActivityResult (当我从洞项目执行时从未调用过):
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Uri selectedImageUri = data.getData();
if (requestCode == SELECT_FILE1)
{
selectedPath1 = getPath(selectedImageUri);
System.out.println("selectedPath1 : " + selectedPath1);
}
if (requestCode == SELECT_FILE2)
{
selectedPath2 = getPath(selectedImageUri);
System.out.println("selectedPath2 : " + selectedPath2);
}
tv.setText("Selected File paths : " + selectedPath1 + "," + selectedPath2);
}
}
这是 logcat 转储:
01-05 15:18:14.569: I/ActivityManager(59): Starting activity: Intent { act=android.intent.action.UPLOADIMAGEDEMO cmp=com.example/.UploadImageDemo }
01-05 15:18:15.779: D/dalvikvm(2496): GC_EXTERNAL_ALLOC freed 2697 objects / 189152 bytes in 92ms
01-05 15:18:16.599: I/ActivityManager(59): Displayed activity com.example/.UploadImageDemo: 1953 ms (total 1953 ms)
01-05 15:18:21.899: D/dalvikvm(279): GC_EXPLICIT freed 871 objects / 134112 bytes in 217ms
01-05 15:18:26.620: I/ActivityManager(59): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) }
01-05 15:18:28.250: I/ActivityManager(59): Starting activity: Intent { act=android.intent.action.GET_CONTENT typ=image/* flg=0x3000000 cmp=com.android.gallery/com.android.camera.ImageGallery }
01-05 15:18:28.670: D/dalvikvm(279): GC_EXTERNAL_ALLOC freed 388 objects / 53352 bytes in 60ms
01-05 15:18:28.850: D/dalvikvm(279): GC_EXTERNAL_ALLOC freed 326 objects / 90664 bytes in 53ms
01-05 15:18:29.200: I/ActivityManager(59): Displayed activity com.android.gallery/com.android.camera.ImageGallery: 873 ms (total 2345 ms)
01-05 15:18:29.420: D/dalvikvm(279): GC_EXTERNAL_ALLOC freed 725 objects / 106960 bytes in 140ms
01-05 15:18:30.430: W/InputManagerService(59): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@45020da8 (uid=10002 pid=279)
01-05 15:18:32.010: D/dalvikvm(112): GC_FOR_MALLOC freed 9994 objects / 476368 bytes in 149ms
最后,我首先从整个项目(退出应用程序)中记录了模拟器的行为,然后从运行良好的分离项目中记录了模拟器的行为。
http://www.youtube.com/watch?v=SntnyKiJQ1Q&feature=youtu.be
非常感谢!!!