Starting just finished activity by resuming opener

Silentsea

Member
Licensed User
Longtime User
Hi there,

I had to develop some own dialog logic, because of some limitations in the dialog lib. For instance I have to create another look and feel.

So in my attempt, I created a code modul for some handling and starting activities. By calling the code moduls method, a dialog activity will be called. After finishing this activity the main activity will resume and I catch the values in Activity_resume and I go further. All worked fine!

But now I have a additonal scenario. And I have to call the same "dialog activity" by catching the values in Activity_resume. The problem now is that the code modul will be fired correctly but from there it goes no further to a new adialog. You could possibly understand it better with a little code.

B4X:
Sub Activity_Resume
   Select Case(cDialog.CallId)
      ...
      Case "EditNote"
         EditNote(False)
      Case "EditNoteToNothing"
         EditNoteToNothing(False)         
   End Select
   
   If cDialog.CallId <> "" Then
   ...
   End If
End Sub

Sub EditNote(CallDialog As Boolean)
   If CallDialog Then
      cDialog.Show("EditNote", "Notiz bearbeiten", "Notiz:", cDialog.DialogType_Input, cDialog.DialogOptions_SaveCancel)
      cDialog.txtValueToStartWith = cPictureNote.GetNote(ActiveNoteId)
      cDialog.txtHint = "Notiz bearbeiten"
   Else
      If cDialog.DialogResult = cDialog.DialogResult_Save Then
         If cDialog.txtValue <> "" Then
            cPictureNote.SaveNote(ActivePictureId, ActiveNoteId, cDialog.txtValue)
            
            'refresh notes scrollview
            BuildScrollViewNotes(ActiveNoteId)
         Else
            'we cannot edit a note to nothing, so we have to note this to customer, maybe he wants to delete
            EditNoteToNothing(True)
            'StartActivity(aDialog)
         End If
      End If
   End If
End Sub

Sub EditNoteToNothing(CallDialog As Boolean)
   If CallDialog Then
      cDialog.Show("EditNoteToNothing", "Warnhinweis", "Sie können diese Notiz nicht ohne Wert speichern, wollen Sie die Notiz löschen?", cDialog.DialogType_Warning, cDialog.DialogOptions_YesNo)
   Else
      If cDialog.DialogResult = cDialog.DialogResult_Yes Then DeleteNote
   End If
End Sub

'in code module:
Sub Show(CallId_ As String, Header_ As String, Content_ As String, DialogType_ As DialogType, DialogOptions_ As DialogOptions)
   ...

   Try
      StartActivity(aDialog)
   Catch
      cTools.Debug("##Exception## " & LastException)
   End Try   
End Sub

I will note, that calling another activity instead of EditNoteToNothing(True) [same activity] will be handled correcty.

Silentsea
 
Last edited:

Silentsea

Member
Licensed User
Longtime User
Thats right, I changed my logic in dialog handling a little bit. So that I can start a message dialog in an input dialog, but the problem will be the same i think.

I also tested to call the method with a little delay (1s) by using timer functionality, then it was working.

Silentsea
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've encountered this issue before. The correct message is sent however Android ignores it. Maybe it is a way to prevent activities to be switched too fast because of older intents. The solution is to use a timer that sends the intent. You should disable this timer in Activity_Pause. This way it will send intents until the next activity is started. I saw cases when it only started after sending 2 or 3 intents.
 
Upvote 0
Top