Android Question Bring Previous Activity (Layout)

Hedi

Member
Hello everyone,

I have an app that play music, if the user playing an audio and closing the app the music still playing, but when the user reopened the app, everything becoming default, just looks like its your first time opening the app, my question is: how can i reopen the last or the previous app, not the new activity, My Code:


My Code:
    Public n As Notification
    n.Initialize
    n.Icon = "icon"
    n.SetInfo("Active", "App Still Open", Main)
    n.Notify(1)
    Service.StartForeground(1,n)

Thank You!
 
Solution
I uploaded my sample project, can you Please do it for me
Replace all your Main activity code with the below code:
B4X:
Sub Process_Globals
    Private xui As XUI
    Public mp As MediaPlayer    
End Sub

Sub Globals
    Private CheckPlay As Boolean = False
    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
     Activity.LoadLayout("Layout")
     If FirstTime Then
        mp.Initialize
    End If
End Sub

Sub Activity_Resume    
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then mp.Stop
End Sub

Sub Button1_Click    
    If CheckPlay = False Then
        mp.Load(File.DirAssets, "Active.mp3")
        mp.Play
        mp.Looping = True
        Button1.Text = "Stop"...

Hedi

Member
Is this a B4XPages project?
Yes

Where is the code that manages the music?
The music code is also in the B4XPages, i have a button that play the music, for example:

Code:
    Private mp As MediaPlayer
    Private CheckPlay as Boolean = False
    
    
    Private Sub Button1_Click
        If CheckPlay = False Then
            mp.Initialize
            mp.Load(File.DirAssets, "Active.wav")
            mp.Play
            mp.Looping = True
            Button1.Text = "Stop"
            CheckPlay = True
        Else
            mp.Stop
            Button1.Text = "Play"
            CheckPlay = False
        End If
    End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I uploaded my sample project, can you Please do it for me
Replace all your Main activity code with the below code:
B4X:
Sub Process_Globals
    Private xui As XUI
    Public mp As MediaPlayer    
End Sub

Sub Globals
    Private CheckPlay As Boolean = False
    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
     Activity.LoadLayout("Layout")
     If FirstTime Then
        mp.Initialize
    End If
End Sub

Sub Activity_Resume    
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then mp.Stop
End Sub

Sub Button1_Click    
    If CheckPlay = False Then
        mp.Load(File.DirAssets, "Active.mp3")
        mp.Play
        mp.Looping = True
        Button1.Text = "Stop"
        CheckPlay = True
    Else
        mp.Stop
        Button1.Text = "Play"
        CheckPlay = False
    End If    
End Sub
1. You mentioned that your project was B4Xpages, but it is not.
2. You were initializing the player in the button click event. That is not the place
3. mp should be declared in Process_Globals
4. When you ask for help, don't address your questions to just one person and make others feel unimportant.
 
Upvote 2
Solution

Hedi

Member
Replace all your Main activity code with the below code:
Thank you so much, today i learned something new, and it works fine <3


1. You mentioned that your project was B4Xpages, but it is not.
No, my real project was B4Xpages, and this is just for example, but now i was changed from B4Xpages to Default project.


2. You were initializing the player in the button click event. That is not the place
Yes, you right, Thank You!


3. mp should be declared in Process_Globals
Okay, Thanks


4. When you ask for help, don't address your questions to just one person and make others feel unimportant.
Sorry for that, I'm new, but in the future i do my best.
 
Upvote 0
Top