Android Question Activity Restarts after YouTubeLibrary fires

Shahid Saeed

Active Member
Licensed User
Longtime User
I am using a splash screen, and app is setup for Full Screen portrait mode, when you play a video it opens in landscape full screen and when quit video the Activity restarts and this time it stays at splash screen.

I have tried to handle through pause sub, resume sub but no luck; Here is the code for your reference:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   
    pnllist.Initialize
    BayanCList.Initialize
   
    If FirstTime Then  
    isFirst = True  
    End If
   
    SplashTimer.Initialize("SplashTimer", 4000)
    SplashTimer.Enabled = True
    Activity.LoadLayout("spalsh")
   
End Sub
Sub Activity_Resume  
    If isFirst = False Then  
        Dim pnl As Panel = BayanList.GetPanel(posBayan-1)
        If pnllist.Size > 0 Then
        For i = 0 To pnllist.Size-1
            Dim p As Panel = pnllist.Get(i)
            p.Color = Colors.Transparent
        Next
        End If
        pnl.Color = pnlBG      
    End If  
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed = True Then
    Activity.Finish
    End If
    posBayan = posBayan
    isFirst = False    
End Sub

Sub SplashTimer_Tick  
    SplashTimer.Enabled = False
    DoEvents
    Activity.RemoveAllViews
    DoEvents
    Activity.LoadLayout("Main")
End Sub
 

MaFu

Well-Known Member
Licensed User
Longtime User
The line "posBayan = posBayan" doesn't make sense because the variable value is replaced with itself, therefore it does nothing.
Can you post the whole project (File > Export As Zip in IDE)?
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
Longtime User
The project file is large:

I have amended the code to see the posBayan value in log this is the result:

B4X:
Installing file.
PackageAdded: package:com.sidso.bayan
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Panel Position: 1 'When App loaded default Position is 1
** Activity (main) Pause, UserClosed = false **
Panel Position: 3 'When Panel Pressed Position changed to 3
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
Panel Position: 1 ' When Video Loaded Position went to default instead of 3
Panel Position: 1
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
Panel Position: 1
Panel Position: 1

This is App Code

B4X:
Sub Activity_Resume  
    If isFirst = False Then  
        Dim pnl As Panel = BayanList.GetPanel(posBayan-1)
        If pnllist.Size > 0 Then
        For i = 0 To pnllist.Size-1
            Dim p As Panel = pnllist.Get(i)
            p.Color = Colors.Transparent
        Next
        End If
        pnl.Color = pnlBG
        Log("Panel Position: " & posBayan)
    End If  
    Log("Panel Position: " & posBayan)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed = True Then
    Activity.Finish
    End If
    posBayan = posBayan
    isFirst = False
    Log("Panel Position: " & posBayan)
End Sub

Sub BayanList_ItemClick (Position As Int, Value As Object)
    Dim pnl As Panel = Value
    If pnllist.Size > 0 Then
        For i = 0 To pnllist.Size-1
            Dim p As Panel = pnllist.Get(i)
            p.Color = Colors.Transparent
        Next
    End If
    pnl.Color = pnlBG
    posBayan = pnl.Tag
    BayanCode = BayanCList.Get(Position)
    YouTube(Position)  
End Sub
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
Longtime User
Where did you create posBayan?
The variable must be dimmed in Process_Globals, otherwise the value get lost on activity destroy/create.

Yes you are right, I dimmed it in Sub Globals, and just moved to Process_Globals and it is working. But there is one thing which I don't know why, If I have selected panel #26; when leave the video panel #26 is selected but I have to scroll and go to its position it's not auto focus on #26?

other than video if I pause the app and load app again it's focus is on#26 no need to scroll. Only when the activity is created again need to scroll. How can I cope with it?
 
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Activity_Resume 
    If isFirst = False Then 
        Dim pnl As Panel = BayanList.GetPanel(posBayan-1)
        If pnllist.Size > 0 Then
        For i = 0 To pnllist.Size-1
            Dim p As Panel = pnllist.Get(i)
            p.Color = Colors.Transparent
        Next
        End If
        pnl.Color = pnlBG
        BayanList.JumpToItem(pnl.Tag)    ' <-------
        Log("Panel Position: " & posBayan)
    End If 
    Log("Panel Position: " & posBayan)
End Sub
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
Longtime User
B4X:
Sub Activity_Resume
    If isFirst = False Then
        Dim pnl As Panel = BayanList.GetPanel(posBayan-1)
        If pnllist.Size > 0 Then
        For i = 0 To pnllist.Size-1
            Dim p As Panel = pnllist.Get(i)
            p.Color = Colors.Transparent
        Next
        End If
        pnl.Color = pnlBG
        BayanList.JumpToItem(pnl.Tag)    ' <-------
        Log("Panel Position: " & posBayan)
    End If
    Log("Panel Position: " & posBayan)
End Sub

Yes it worked i just had to amend the code a bit

B4X:
BayanList.JumpToItem(pnl.Tag-1)
 
Upvote 0
Top