Android Question [SOLVED] Dialogs crash when Activity_Pause

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
I am not able to fix that alone. Perhaps would you have some ideas.

I am willing to open a dialog after having chosen an image file using ContentChooser. But when returning from the ContentChooser, if the activity is paused after the dialogs had been shown, I get a crash.

main$ResumeMessagerun (java line: 298)
java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.objects.ActivityWrapper b4a.example.debug.main._activity' on a null object reference
at b4a.example.debug.main$ResumeMessage.run(main.java:298)
at android.os.Handler.handleCallback(Handler.java:815)
...

The sample project does it :
  • press the push button and select an image
  • after having selected the image a message box appears
  • press the device's Home button to put the Activity in Pause and get the crash
I have tried several methods like using CallSubDelayed or CallSubPlus to get a longer delay before showing the dialog but nothing fixes (even a long delay because the dialog is a modal one).

Any idea please ? Thanks
 

Attachments

  • sample.zip
    6.9 KB · Views: 288
Last edited:

JordiCP

Expert
Licensed User
Longtime User
Try this :)

B4X:
Sub Globals
  Dim flg_success as Boolean=False
End Sub

Sub Activity_Resume
    If flg_success=True Then 
        Msgbox("Please press the Home button to make me crash","Try it")
        flg_success=False
    End If
End Sub

'image selected, opens a dialog
Sub CC_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then
        flg_success=True
    End If
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
A useful workaround, Jordi, thank you; but what is the cause of the malfunction?

Surely this crash happens only with msgbox; I tried displaying a simple panel instead of it and the app does not crash (attached)
 

Attachments

  • crdialogs 2.zip
    8.1 KB · Views: 296
Last edited:
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
... and then...?
The solution you propose (using a Panel, or a custom dialog based on a panel) works great of course. But in case of a modal dialog (which holds the main thread till it is closed) we get the difficulty reported.
Too tired yesterday, I was not able to find the solution to let the Activity_Resume :)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Yes, but my question is: why a modal dialog can cause that kind of error?

It should be something related to Android or B4A, but what?

I think we need a special Guru's answer; guess who ;)
[or someone should search and study further; I'm not in the mood, now :)]


Thanks, lemon
 
Upvote 0
Top