Java Question Is it possible to get a listener for OnActivityResult (From B4A)?

NFOBoy

Active Member
Licensed User
Longtime User
Erel, in looking at making sure I'm doing things (the sortof) right way, found this from the gentleman who did many of the sample on Google Game Services:

BaseGameActivity is a pretty simple wrapper around GameHelper, which is the object that really does all the work. If you can't derive from BaseGameActivity, simply use GameHelper directly. The implementation of the BaseGameActivity class can serve as an example of how to hook up the GameHelper methods to your Activity's lifecycle.

In summary:

in your Activity's onCreate, create the GameHelper object.
from your Activity's onStart, call GameHelper's onStart
from your Activity's onStop, call GameHelper's onStop.
from your Activity's onActivityResult, call GameHelper's onActivityResult.
implement the GameHelperListener interface methods

In wrapping this library, I have discovered:

For B4A, we most definitely have onCreate and onStart, onStop... hmmm sort of. (still wrapping my head around what to do, when based on B4A structure for onStop)

The GameHelperListener is straightforward enough (as are other listeners, once you get the hang of it)

For the onActivityResult I have seen, and implemented thanks to your sample code for the ion structure. (also fairly straight forward, in that if following the code sample, can get a callback registered for a specific onActivityResult, if the call is made directly from our code)

My other question (which is on here, so sorry if this is considered a duplicate) deals with trying to get the onActivityResult from something we can't call the startActivityForResult directly. (which I still haven't understood how to do yet, your potential workaround not withstanding)

I'm just wondering, in the case of where it is called inside a library, then the OnActivityResult for the BA.activity is being called, right? If so, is it possible to make it so that we could register a listener on the BA, and that way get the OnActivityResults called all the time?

My thought would be that if your class wants the onActivityResult, then register a listener with BA.activity, and then for all future StartActivityForResult calls, the BA.activity is registered (as it is really the activity we are dealing with) and then when the result is returned, BA.activity calls our listener(s).

Then each listener looks at the results and decides whether any action needs to take place. Kind of like this:
B4X:
/**
     * Handle activity result. Call this method from your Activity's
     * onActivityResult callback. If the activity result pertains to the sign-in
     * process, processes it appropriately.
     */
    public void onActivityResult(int requestCode, int responseCode, Intent intent) {
        if (requestCode == RC_RESOLVE) {
            // We're coming back from an activity that was launched to resolve a
            // connection
            // problem. For example, the sign-in UI.
            mExpectingActivityResult = false;
            debugLog("onActivityResult, req " + requestCode + " response " + responseCode);
            if (responseCode == Activity.RESULT_OK) {
                // Ready to try to connect again.
                debugLog("responseCode == RESULT_OK. So connecting.");
                connectCurrentClient();
            } else {
                // Whatever the problem we were trying to solve, it was not
                // solved.
                // So give up and show an error message.
                debugLog("responseCode != RESULT_OK, so not reconnecting.");
                giveUp();
            }
        }
    }

Am I off my rocker to much?

Ross
 
Top