onActivityResult仅被识别为变量

时间:2012-12-20 12:37:53

标签: java android android-intent methods

创建onActivityResult方法时,Eclipse只是将其识别为某个未公布原因的变量。

protected void onActivityResult(int resultCode, int requestCode, Intent data){

    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == Class_2.RESULT_CODE && requestCode == REQUEST_CODE) {
        if (data.hasExtra("returnKey1")) {
            int number = number + getIntent().getExtras().getInt("returnKey1");
        }
    }
}

通过" onActivityResult "它只是给了我一个错误,消息" void是变量onActivityResult的无效类型"任何想法?

4 个答案:

答案 0 :(得分:2)

我不知道你班上还有什么,但试着改变

protected void onActivityResult(int resultCode; int requestCode; Intent data)

protected void onActivityResult(int resultCode, int requestCode, Intent data)

您还应该打电话给:

super.onActivityResult(requestCode, resultCode, data);

答案 1 :(得分:1)

将其纳入方法

super.onActivityResult(requestCode, resultCode, data);

答案 2 :(得分:1)

使用此模板覆盖活动的onActivityResult

@Override
protected void onActivityResult(int resultCode, int requestCode, Intent data)
{                   
    super.onActivityResult(requestCode, resultCode, data);

    // do your work here
}

并从";"的参数中删除半con onActivityResult,并确保在Activity类中覆盖onActivityResult方法

答案 3 :(得分:0)

您使用分号;分隔其参数时声明方法不正确,而它应该只是冒号,。所以它应该是:

protected void onActivityResult(int resultCode, int requestCode, Intent data)

而不是

protected void onActivityResult(int resultCode; int requestCode; Intent data)