Hedi Member Oct 26, 2021 #1 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: 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!
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: 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 M M Mahares Oct 27, 2021 Hedi said: I uploaded my sample project, can you Please do it for me Click to expand... Replace all your Main activity code with the below code: Code: 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 said: I uploaded my sample project, can you Please do it for me Click to expand... Replace all your Main activity code with the below code: Code: 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"...
Erel B4X founder Staff member Licensed User Longtime User Oct 27, 2021 #2 Is this a B4XPages project? Where is the code that manages the music? Upvote 0
Hedi Member Oct 27, 2021 #3 Erel said: Is this a B4XPages project? Click to expand... Yes Erel said: Where is the code that manages the music? Click to expand... 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
Erel said: Is this a B4XPages project? Click to expand... Yes Erel said: Where is the code that manages the music? Click to expand... 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
Erel B4X founder Staff member Licensed User Longtime User Oct 27, 2021 #4 Please run your app, reproduce it, and post the logs. The solution might be to add another activity that will just be used as the notification target and call the main activity when the second activity is created: Code: StartActivity(Main) Activity.Finish Upvote 0
Please run your app, reproduce it, and post the logs. The solution might be to add another activity that will just be used as the notification target and call the main activity when the second activity is created: Code: StartActivity(Main) Activity.Finish
Hedi Member Oct 27, 2021 #5 Hello @Erel I uploaded my sample project, can you Please do it for me, I appreciate it. Download the Project Upvote 0
Hello @Erel I uploaded my sample project, can you Please do it for me, I appreciate it. Download the Project
M Mahares Expert Licensed User Longtime User Oct 27, 2021 #6 Hedi said: I uploaded my sample project, can you Please do it for me Click to expand... Replace all your Main activity code with the below code: Code: 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 said: I uploaded my sample project, can you Please do it for me Click to expand... Replace all your Main activity code with the below code: Code: 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.
Hedi Member Oct 27, 2021 #7 Mahares said: Replace all your Main activity code with the below code: Click to expand... Thank you so much, today i learned something new, and it works fine <3 Mahares said: 1. You mentioned that your project was B4Xpages, but it is not. Click to expand... No, my real project was B4Xpages, and this is just for example, but now i was changed from B4Xpages to Default project. Mahares said: 2. You were initializing the player in the button click event. That is not the place Click to expand... Yes, you right, Thank You! Mahares said: 3. mp should be declared in Process_Globals Click to expand... Okay, Thanks Mahares said: 4. When you ask for help, don't address your questions to just one person and make others feel unimportant. Click to expand... Sorry for that, I'm new, but in the future i do my best. Upvote 0
Mahares said: Replace all your Main activity code with the below code: Click to expand... Thank you so much, today i learned something new, and it works fine <3 Mahares said: 1. You mentioned that your project was B4Xpages, but it is not. Click to expand... No, my real project was B4Xpages, and this is just for example, but now i was changed from B4Xpages to Default project. Mahares said: 2. You were initializing the player in the button click event. That is not the place Click to expand... Yes, you right, Thank You! Mahares said: 3. mp should be declared in Process_Globals Click to expand... Okay, Thanks Mahares said: 4. When you ask for help, don't address your questions to just one person and make others feel unimportant. Click to expand... Sorry for that, I'm new, but in the future i do my best.