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:
    Code:
    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:
    Code:
    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
     
  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..

    Thanks,
    Walter
     
  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
    Code:
    Intent intent;
    intent = mTransactionController.performBalanceInquiry();
    ba.startActivityForResult(ion, 
    intent);
    This works perfect for me.

    Thanks,
    Walter
     
Loading...
  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