Java Question Referencing a activity from a library

DonManfred

Expert
Licensed User
Longtime User
I´m doing a wrap for https://github.com/EdwardvanRaak/MaterialBarcodeScanner

The lib is using a Builder to build the component properties. So far no problem.
I need to pass a Activity at some place.

There is also a entry for the manifest i need to add

i tried it with

B4X:
AddManifestText(<activity
            android:theme="@style/AppTheme.NoActionBar"
            android:name=".com.edwardvanraak.materialbarcodescanner.MaterialBarcodeScannerActivity"
            android:label="@string/library_name" >
        </activity>)
or
B4X:
AddManifestText(<activity
            android:theme="@style/AppTheme.NoActionBar"
            android:name=".MaterialBarcodeScannerActivity"
            android:label="@string/library_name" >
        </activity>)

but i always get this error

android.content.ActivityNotFoundException: Unable to find explicit activity class {de.amberhome.appcompat.example1/com.edwardvanraak.materialbarcodescanner.MaterialBarcodeScannerActivity}; have you declared this activity in your AndroidManifest.xml?

de.amberhome.appcompat.example1 is the packagename of the AppCompat example i use to create an example


Any hints are highly welcome ;-)
 

Attachments

  • MaterialBarcodesrc.zip
    68.7 KB · Views: 231

DonManfred

Expert
Licensed User
Longtime User
Thank you for your answer. But it does not really change anything.

I´ve changed manifest to
B4X:
AddManifestText(<activity
            android:theme="@style/AppTheme.NoActionBar"
            android:name="com.edwardvanraak.materialbarcodescanner.MaterialBarcodeScannerActivity"
            android:label="@string/library_name" >
        </activity>)

In b4a i use a MaterialBarcodeScannerBuilder to build the MaterialBarcodeScanner object.
With the MaterialBarcodeScanner i then can start a barcodescan

B4X:
Sub Button1_Click
    Log("Button1 Click event fired")
    scanner.startScan
End Sub

startScan in the wrapper is defined as
B4X:
 public void startScan(final BA ba){
      getObject().startScan();
  }
startScan in the MaterialBarcodeLibrary is defined as

B4X:
    public void startScan() {
        EventBus.getDefault().register(this);
        if (mMaterialBarcodeScannerBuilder.getActivity() == null) {
            throw new RuntimeException(
                    "Could not start scan: Activity reference lost (please rebuild the MaterialBarcodeScanner before calling startScan)");
        }
        int mCameraPermission = ActivityCompat.checkSelfPermission(
                mMaterialBarcodeScannerBuilder.getActivity(),
                Manifest.permission.CAMERA);
        if (mCameraPermission != PackageManager.PERMISSION_GRANTED) {
            requestCameraPermission();
        } else {
            // Open activity

            BA.Log("EventBus.postSticky"); // Added to get more infos
            EventBus.getDefault().postSticky(this);
            BA.Log("Create intent"); // Added to get more infos
            Intent intent = new Intent(mMaterialBarcodeScannerBuilder.getActivity(), MaterialBarcodeScannerActivity.class);
            BA.Log("startActivity"); // Added to get more infos
            mMaterialBarcodeScannerBuilder.getActivity().startActivity(intent);
        }
    }


B4X:
            BA.Log("EventBus.postSticky");
            EventBus.getDefault().postSticky(this);
            BA.Log("Create intent");
            Intent intent = new Intent(mMaterialBarcodeScannerBuilder.getActivity(), MaterialBarcodeScannerActivity.class);
            BA.Log("startActivity");
            mMaterialBarcodeScannerBuilder.getActivity().startActivity(intent);
when i pres the button in my app at the end the startScan method in MaterialBarcodeScanner.java is called. The result is then the same same error as before

 

DonManfred

Expert
Licensed User
Longtime User
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…