Java Question Pass activity as parameter

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hi

I need to use an B4A activity instance in a B4A library.
What is the correct way to do this?

B4X:
public void SaveTag(ActivityWrapper activity) {
Activity act = activity.getObject(); //getObject() is a BALayout
}

I need an activity instance to pass for enabling foreground dispatch on that activity

public void enableForegroundDispatch (Activity activity, PendingIntent intent, IntentFilter[] filters, String[][] techLists)

Regards,
Tomas
 

raphael75

Active Member
Licensed User
Longtime User
Here is the code I have used for enabling foreground dispatch in the NfcForeground library (http://www.b4x.com/android/forum/threads/nfcforeground-library-nfc-foreground-dispatch-system.31141):

B4X:
public void EnableForeground(BA ba) throws IllegalStateException {
    Context thisActivityContext = ba.context;
    NfcAdapter nfcDefAdapter = NfcAdapter.getDefaultAdapter(thisActivityContext);
    // If NFC Adapter exists Then enable Foreground Dispatch
    if (nfcDefAdapter != null) {
        Activity thisActivity = ba.activity;
        Intent thisActivityIntent = new Intent(thisActivityContext, thisActivityContext.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(thisActivityContext, 0, thisActivityIntent, 0);
        nfcDefAdapter.enableForegroundDispatch(thisActivity, pendingIntent, null, null);
    }
}
 
Top