Question

I am trying to setResult on my "Register" Button, but nothing happens:

SignInActivity:

Start activity for result:

Intent intent = RegisterActivity_.intent(this).get();
this.startActivityForResult(intent, REQUEST_CODE_USER_REGISTER);

On Activity Result

@OnActivityResult(REQUEST_CODE_USER_REGISTER)
protected void onResult(int resultCode) {
    if (resultCode == RESULT_OK)
        DashboardActivity_.intent(this).start();
    else if (resultCode == RESULT_CANCELED) {
        this.showDialogAlert("Unexpected error", null);
}

RegisterActivity:

this.setResult(RESULT_OK);

I am using AndroidAnnotations and I'm not using the this.finish() method because it set the property android:noHistory="true" in all Activities on AndroidManifest.xml. I am also setting the parent of each activity there. Have tried to remove these settings and setResult continued without work. Has anyone experienced this?

Était-ce utile?

La solution

I am using AndroidAnnotations and I'm not using the this.finish() method because it set the property android:noHistory="true"in all Activities on AndroidManifest.xml.

I think your issue is here. When you're using startActivityForRestult, the expected workflow is to launch a new activity, do some work and then close this activity to go back to the previous one with the result of the work. So, you can't use android:noHistory="true" here because it doesn't make any sense.

Also, if you look at Activity's source code, you'll see that result is propagated from the finish method.

Autres conseils

Start Activity for Result. your code is Ok

Intent intent = RegisterActivity_.intent(this).get();
this.startActivityForResult(intent, REQUEST_CODE_USER_REGISTER);

Now Inside the Activity that you start for the result set the result status like below code.

setResult(resultCode); result status possible values are like RESULT_CANCELED,RESULT_OK.etc

Activity that starts the new activity for result must override the below method and this method work when the activity that started for result finish.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
}

I think the method is..

onActivityResult(int requestCode, int resultCode, Intent data)

not onResult

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top