【发布时间】:2011-10-04 23:11:30
【问题描述】:
我在从活动返回信息时遇到困难,我对实施的理解不完整。
我想要的是用户能够单击一个按钮来加载 android 库,选择一个图像,该图像(或可能是图像的链接)被转换为一个位图/可绘制的,它出现在我的活动的 UI 中布局。
我打开了 android 图库,但我没有收到任何回复(我知道为什么,图库应用中没有意图 - 我无权访问以进行编辑,但我不知道解决方案)
ImageView galleryClick = (ImageView)findViewById(R.id.addgallery);
profilePic = (ImageView)findViewById(R.id.profilepic);
galleryClick.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);
}
});
我希望 onActivityFinished 会在我的手写活动中被调用,但该方法从未被调用(我在其代码中放置了一个断点
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
// currImageURI is the global variable I'm using to hold the content:// URI of the image
//currImageURI = data.getData();
}
}
}
解决方案?
【问题讨论】:
-
断点并不总是受到尊重,具体取决于您从 IDE 启动应用程序的方式。在 requestCode==1 块中抛出一条日志消息 - that 出现了吗?
标签: android android-activity gallery