Android Question How to prevent the second Activity from closing when the Slider is on

desof

Well-Known Member
Licensed User
Longtime User
Hello, I am working on an adaptation of the Erel project of this link
https://www.b4x.com/android/forum/threads/b4x-xui-imageslider.87128/#content

I find the problem that when calling another activity (StartActivity (Menu)) on some occasions Activity 1 (Main) kills Activity2 (Menu).

It seems that the event that shows the next Slider keeps running and at the end it becomes pop-up.

I tried to put timer1.Enabled = False before calling but it happens anyway.

B4X:
Sub Button1_Click
    timer1.Enabled=False
    StartActivity (Menu)
End Sub

What can I do to avoid this?

I attach the project

NOTE Sometimes you have to try several times to make this happen.
 

Attachments

  • SliderB4A.zip
    43.8 KB · Views: 691

Erel

B4X founder
Staff member
Licensed User
Longtime User
I find the problem that when calling another activity (StartActivity (Menu)) on some occasions Activity 1 (Main) kills Activity2 (Menu)
It doesn't kill the second activity. It only brings the first one to the front.

The problem is in ImageSlider1_GetImage. When the http response arrives it will cause Main activity to start (because of a CallSubDelayed call in HttpJob). The solution is to make the requests from the starter service.

Check the attached example.
 

Attachments

  • Slider.zip
    43.8 KB · Views: 1,586
Upvote 0

desof

Well-Known Member
Licensed User
Longtime User
In what way can I read all the jpg files that are in a certain remote folder?
I think in this Sub you should do it

B4X:
Public Sub FindImages (root As String) As ResumableSub
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(root)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim str As String = j.GetString
        Dim rb As RegexBuilder
        rb.Initialize
        rb.AppendEscaped("<img").Append(rb.CharAny).AppendZeroOrMore.AppendEscaped($"src=""$).StartCapture
        rb.AppendAnyBut(Array($"""$)).AppendAtLeastOne.EndCapture.Append(rb.CharQuote)
        Log(rb.Pattern)
        Dim m As Matcher = Regex.Matcher2(rb.Pattern, Regex.MULTILINE, str)
        Do While m.Find
            Dim link As String = m.Group(1)
            If link.StartsWith("http") = False Then
                If link.StartsWith("/") = False Then link = "/" & link
                link = root & link
            End If
            Main.urls.Add(link)
        Loop
    End If
    j.Release
    Return j.Success
End Sub
 
Upvote 0

nickysuwandi

Member
Licensed User
Longtime User
In what way can I read all the jpg files that are in a certain remote folder?
I think in this Sub you should do it

B4X:
Public Sub FindImages (root As String) As ResumableSub
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(root)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim str As String = j.GetString
        Dim rb As RegexBuilder
        rb.Initialize
        rb.AppendEscaped("<img").Append(rb.CharAny).AppendZeroOrMore.AppendEscaped($"src=""$).StartCapture
        rb.AppendAnyBut(Array($"""$)).AppendAtLeastOne.EndCapture.Append(rb.CharQuote)
        Log(rb.Pattern)
        Dim m As Matcher = Regex.Matcher2(rb.Pattern, Regex.MULTILINE, str)
        Do While m.Find
            Dim link As String = m.Group(1)
            If link.StartsWith("http") = False Then
                If link.StartsWith("/") = False Then link = "/" & link
                link = root & link
            End If
            Main.urls.Add(link)
        Loop
    End If
    j.Release
    Return j.Success
End Sub

May be i can sharing my code for you, i had same problem to got jpg file in certain remote folder, i had add this code below, may this help you

B4X:
rb.Initialize.AppendEscaped("""").Append(rb.CharAny).AppendAtLeastOne.AppendEscaped(".jpg""")
        Dim m As Matcher = Regex.Matcher2(rb.Pattern, Regex.MULTILINE, str)
        Do While m.Find
            Dim link As String = m.Group(0).Replace("""","")
            If link.StartsWith("http") = False Then
                If link.StartsWith("/") = False Then link = "/" & link
                link = root & link
            End If
            MainMenu.urlspromo.Add(link)
        Loop
 
Upvote 0
Top