Java Question onActivityResults Help

Discussion in 'Libraries developers questions' started by walterf25, Apr 11, 2019.

  1. walterf25

    walterf25 Well-Known Member Licensed User

    Hello everyone, i'm currently trying to wrap a library for a POS system, the device has a built in app which makes it really easy to do all the Transactions between customer and banks, the app is called using a number of intents, they have provided a Class which defines all the actions and extra data for the intents.

    My question is, i am trying to get the results after a transaction has been performed, i have the following code which i took from one of @Erel's tutorials but all i get is the following:

    the code i am using is this:
    public void PerformBalanceInquiry(BA ba) {
    //This line 
    is calling the performBalanceInquiry defined in the TransactionController class which is made up of an intent.
            ion = new IOnActivityResult() {
    public void ResultArrived(int arg0, Intent arg1) {
                    // TODO Auto-generated method stub
    "ResultArrived: " + arg0 + " --- " + arg1.getDataString());
            try {
                 ba.startActivityForResult(ion, null); //<-- passing null instead of an intent
              } catch (NullPointerException npe) {
                 // mba.setLastException(npe);
                  BA.Log("nullpointerexception: " + npe.getMessage().toString());
             // BA.SharedProcessBA sba = mba.sharedProcessBA;
              BA.SharedProcessBA sba = ba.processBA.sharedProcessBA;
              try {
                 Field f = sba.getClass().getDeclaredField("onActivityResultMap");
                 if (f.get(sba) == null) {
                     f.set(sba, new HashMap<Integer, WeakReference<IOnActivityResult>>());
                    HashMap<Integer, WeakReference<IOnActivityResult>> onActivityResultMap = (HashMap<Integer, WeakReference<IOnActivityResult>>) f.get(sba);
                    BA.Log("onActivityResultMap: " + onActivityResultMap.size());
                // int requestCode = f.getInt(sba) - 1;
                // BA.Log("requestcode: " + requestCode);
                 //requestCode holds the value that should be used to send the intent.
              } catch (Exception e) {
                 throw new RuntimeException(e);
    The code from the TransactionController class for the performBalanceInquiry is the following:
    public void performBalanceInquiry() {
    Intent intent = new Intent(ACTION_BALANCE_INQUIRY);
    intent.putExtra(KEY_AUTO_PRINT, mAutoPrint);
    "gettingpackage name: " + mActivity.getPackageManager().toString());
    if(intent.resolveActivity(mActivity.getPackageManager()) != null) {
    "After BalanceInquiry: " + REQUEST_CODE_BALANCE_INQUIRY);
            else {
               // Toast.makeText(mActivity, mActivity.getString(R.string.no_activity_handle), Toast.LENGTH_SHORT).show();
                BA.Log("No Activity_Handle");
    does anyone know why the result is null, does my code look fine?

    Does anyone have any suggestions?

  2. Erel

    Erel Administrator Staff Member Licensed User

  3. walterf25

    walterf25 Well-Known Member Licensed User

    Hi Erel, i was trying to avoid having to call the intents myself from within B4A as there are around more than 10 functions that are being called with intents and the manufacturer already provides a class where everything is already defined including all the intent actions and result keys etc..

  4. Erel

    Erel Administrator Staff Member Licensed User

    It will probably be simpler to send the intents yourself from the wrapper.
    walterf25 likes this.
  5. walterf25

    walterf25 Well-Known Member Licensed User

    I ended up modifying the class where all the Intents are being sent from by changing the public void to public Intent so that I can pass the intent like this
    Intent intent;
    intent = mTransactionController.performBalanceInquiry();
    This works perfect for me.

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice