简体   繁体   中英

onActivityResult is not called from class where startActivityForResult is called

I have a MainActivity, one NonActivity class and SearchActivity. NonActivity class calls startActivityForResult, but onActivityResult in nonActivity class is never called.

But I figured it out, that is called in MainActivity, when I implemented it for testing purposes. Could you please tell me if it is possible, that onActivityResult will be called from nonActivity class?

This is the code I am calling from NonActivity class.

Intent intent = new Intent(activity, SearchActivity.class);
        //start SearchActivity through intent and expect for result. The result is based on result code, which is REQUEST_DISCOVERY 
        activity.startActivityForResult(intent, REQUEST_DISCOVERY);
    }

Thanks for your answer, if you need more code, I can put add.

onActivityResult() won't be called on a NonActivity class, because actually it wasn't the one that started the new Activity , your calling startActivityForResult() on your MainActivity object and MainActivity is where the onActivityResult() will be called. To call it back to the NonActivity just create a method inside the NonActivity and call it from the MainActivity's onActivityResult() , passing the arguments that you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM