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

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Button1 Click event fired
EventBus.postSticky
Create intent
startActivity
main_button1_click (java line: 357)
android.content.ActivityNotFoundException: Unable to find explicit activity class {de.donmanfred.barcode/com.edwardvanraak.materialbarcodescanner.MaterialBarcodeScannerActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1854)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1545)
at android.app.Activity.startActivityForResult(Activity.java:4283)
at android.app.Activity.startActivityForResult(Activity.java:4230)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:843)
at android.app.Activity.startActivity(Activity.java:4567)
at android.app.Activity.startActivity(Activity.java:4535)
at com.edwardvanraak.materialbarcodescanner.MaterialBarcodeScanner.startScan(MaterialBarcodeScanner.java:83)
at de.donmanfred.MaterialBarcodeScannerWrapper.startScan(MaterialBarcodeScannerWrapper.java:62)
at de.donmanfred.barcode.main._button1_click(main.java:357)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5697)
at android.widget.TextView.performClick(TextView.java:10814)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
android.content.ActivityNotFoundException: Unable to find explicit activity class {de.donmanfred.barcode/com.edwardvanraak.materialbarcodescanner.MaterialBarcodeScannerActivity}; have you declared this activity in your AndroidManifest.xml?
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
 

DonManfred

Expert
Licensed User
Longtime User
Last edited:
Top