Java Question onActivityResults Help

walterf25

Expert
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:

onActivityResult wii null
the code i am using is this:
B4X:
public void PerformBalanceInquiry(BA ba) {
//This line is calling the performBalanceInquiry defined in the TransactionController class which is made up of an intent.
    mTransactionController.performBalanceInquiry();
        
        ion = new IOnActivityResult() {
            @Override
            public void ResultArrived(int arg0, Intent arg1) {
                // TODO Auto-generated method stub
                BA.Log("ResultArrived: " + arg0 + " --- " + arg1.getDataString());
            }
            
        };
        
        try {
             ba.startActivityForResult(ion, null); //<-- passing null instead of an intent
          } catch (NullPointerException npe) {
             //required...
             // 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");
             f.setAccessible(true);
             if (f.get(sba) == null) {
                 f.set(sba, new HashMap<Integer, WeakReference<IOnActivityResult>>());
                
                @SuppressWarnings("unchecked")
                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:
B4X:
    public void performBalanceInquiry() {
        Intent intent = new Intent(ACTION_BALANCE_INQUIRY);
        intent.putExtra("dummy", "dummy");
        intent.putExtra(KEY_AUTO_PRINT, mAutoPrint);
        intent.setType("text/plain");
        BA.Log("gettingpackage name: " + mActivity.getPackageManager().toString());
        if(intent.resolveActivity(mActivity.getPackageManager()) != null) {
            mActivity.startActivityForResult(intent, REQUEST_CODE_BALANCE_INQUIRY);
            BA.Log("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?

Thanks,
Walter
 

walterf25

Expert
Licensed User
You don't need the "complicated" code. Follow the code from the first post: https://www.b4x.com/android/forum/threads/java-guide-using-onactivityresult.7297/
Send the intent yourself.
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..

Thanks,
Walter
 

walterf25

Expert
Licensed User
It will probably be simpler to send the intents yourself from the wrapper.
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
B4X:
Intent intent;
intent = mTransactionController.performBalanceInquiry();
ba.startActivityForResult(ion, intent);
This works perfect for me.

Thanks,
Walter
 
Top