为什么onActivityResult
没有运行?
任何人都可以帮忙吗?
我的课程名称只有MainActivity
这是我的代码
public class MainActivity extends Activity{
public static final int CROP = 1;
private static final String TAG = MainActivity.class.getCanonicalName();
private ImageView imgView;
private Button selectBtn;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgView = (ImageView)findViewById(R.id.imgView);
hasilET = (EditText)findViewById(R.id.hasilET);
selectBtn = (Button)findViewById(R.id.selectBtn);
selectBtn.setOnClickListener(new ClickSelect());
}
public class ClickSelect implements View.OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.v(TAG, "CLICK");
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("image/*");
i.putExtra("crop", "true");
i.putExtra("aspectX", 0);
i.putExtra("aspectY", 0);
i.putExtra("outputX", 200);
i.putExtra("outputY", 150);
i.putExtra("return-data", true);
startActivityForResult(i, CROP);
}
public void onActivityResult(int requestCode, int resultCode, Intent data){
Log.v(TAG, "crop");
Bitmap bmp;
if(requestCode==1){
if(data != null){
Bundle extras = data.getExtras();
bmp = extras.getParcelable("data");
imgView.setImageBitmap(bmp);
}
}
}
}
}
答案 0 :(得分:0)
快速查看代码之后的Jsut:
似乎正确,如果在
中替换CROP会发生什么startActivityForResult(i, CROP);
有一个号码?
中使用相同的数字 if(requestCode==CROP)
并且可能删除此行:
i.putExtra("crop", "true")
答案 1 :(得分:0)
您应该覆盖onActivityResult()
班级中的MainActivity
将onActivityResult()
从班级ClickSelect
移至MainActivity
使用此示例:Example
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CROP) {
if (resultCode == RESULT_OK) {
...
}
}