对于ABC类型,方法startActivityForResult(Intent,int)未定义

时间:2015-04-30 10:22:53

标签: android android-layout android-image android-alarms android-layout-weight

我有一个带有实现Serializable的ABC类 ABC类是一个警报类,所以使用一堆函数,我只是想从SD卡上传图像,我需要在GRIDVIEW中查看图像然后用户需要选择图像,这是处理 我有一个名为getImage()的方法来从SD卡中获取图像..

  public void getImage() {

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);

}   

收到错误The method startActivityForResult(Intent, int) is undefined for the type ABC 我怎么能纠正这个?

2 个答案:

答案 0 :(得分:0)

Short version: startActivityForResult() is only available from inside an activity or a fragment.

If you post more details about what you are trying to achieve I may be able to give you a more helpful answer

答案 1 :(得分:0)

接受非活动类中的<div class="timeline">并将其转换为context

Activity

然后在任何你想要的地方打电话

 private Context context;
 private Activity activity;

public Example(Context context) {
    this.context = context;
    this.activity = (Activity) context;
}

如果您希望稍后获得结果,请在非活动类中定义用户定义的activity.startActivityForResult()

onActivityResult()

并将活动类的结果传递给用户定义的public void onActivityResult(int requestCode, int responseCode, Intent intent) {} 方法

onActivityResult()