Android Question Failure to recognize code module methods

Hello
I use the following code in Service_Create in my starter to send a notification with firebase:

B4X:
Sub Service_Create
    Try
        CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
    Catch
    End Try
End Sub
There are also functions in this service (starter).
In these functions, methods from the code module are called:
B4X:
Sub Download(token As String)
    Dim MyDownloadLink As String = MyModuleCode.GetLink
    Dim encryptedToken As String = MyModuleCode.encrypt(token)
    
    Dim http As HttpJob
    http.Initialize("http",Me)
    http.Download(MyDownloadLink&"?token="&encryptedToken)
End Sub
I call the download method from the main activity:
B4X:
Private Sub Button1_Click
    Starter.Download(MyToken)
End Sub
The first time I ran the app and clicked on Button1, the download was completed and everything worked properly.
I exited the app (I also clear it from the recent list) and entered the app again. The second time it worked correctly and I exited again.
But for the third time when I entered the app and clicked on Button1, the following error appeared:
B4X:
*** Service (starter) Create ***
stopping spontaneous created service
** Service (starter) Destroy (ignored)**
sending message to waiting queue (CallSubDelayed - SubscribeToTopics)
** Activity (main) Create (first time) **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create (first time) **
** Activity (main) Resume **
starter_Download (java line: 153)
java.lang.NullPointerException: Attempt to read from field 'b4a.example.MyModuleCode b4a.example.starter._MyModuleCode' on a null object reference in method 'java.lang.String b4a.example.starter._Download(java.lang.String, java.lang.String, java.lang.String, long, java.lang.Object)'
    at b4a.example.starter._Download(starter.java:153)
    at b4a.example.main$ResumableSub_t_ResponseBody.resume(main.java:3797)
    at b4a.example.main._t_responsebody(main.java:3072)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1114)
    at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:1077)
    at b4a.example.MyModuleCode3$ResumableSub_t_onNext.resume(MyModuleCode3.java:399)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1748)
    at android.os.Handler.handleCallback(Handler.java:958)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:230)
    at android.os.Looper.loop(Looper.java:319)
    at android.app.ActivityThread.main(ActivityThread.java:8893)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
java.lang.NullPointerException: Attempt to read from field 'b4a.example.MyModuleCode b4a.example.starter._MyModuleCode' on a null object reference in method 'java.lang.String b4a.example.starter._Download(java.lang.String, java.lang.String, java.lang.String, long, java.lang.Object)'
I also created a separate service to call the SubscribeToTopics method using callsub.
But it had no effect and this error occurred regularly after opening and closing the app two or three times.
Why does this happen? how to solve

Another question!
If I Remove the FirebaseMessaging service, but the Firebase permissions remain in the manifest, can I still send notifications to users from the Firebase console or analyze their activity? Or will there be a disturbance?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why waste your time with activities and services??? Switch to B4XPages and forget from such complexities.

The problem is here:
*** Service (starter) Create ***
stopping spontaneous created service
** Service (starter) Destroy (ignored)**

Something caused the starter service to be started and it was then destroyed. This is all that I can say based on the provided code.
 
Upvote 0
Thank you, Mr. Engineer
Yes, I use B4XPages in new projects, but this problem occurred in one of my old projects that I wanted to update.

I feel that this line of code will destroy the service:
B4X:
CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
Because when I remove this line of code, the problem is solved.

If I remove this line of code, can I still send notifications from the firebase console or use the analysis section? Will there be no errors or disturbances?

What should I do to solve the problem?
 
Upvote 0
If I remove the FirebaseMessaging service as well as the following line from my project:
B4X:
CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
But the Firebase permissions remain in the manifest:
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile(Macro, FirebaseAnalytics.FirebaseAnalytics)

AddApplicationText(
<meta-data android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
)

AddApplicationText(
<meta-data android:name="com.google.android.gms.ads.AD_MANAGER_APP" android:value="true" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<activity
    android:name="com.google.android.gms.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:theme="@android:style/Theme.Translucent" />)
Can I still send notifications to users or analyze their activity from the Firebase console? Or will there be a disruption?šŸ¤”
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Don't use Firebase console to send messages. There are cases where it will not work. Use the B4J sending tool.

You need to call SubscribeToTopics in order to subscribe the user to the relevant topics. Once subscribed it will work and the subscription state is kept.

Can you post the full code in the starter service?
 
Upvote 0
Top