Emme Developer Well-Known Member Licensed User Longtime User Oct 12, 2018 #1 Hi to all! Is there a way to know when application goes in background? I want to stop mediaplayer when app goes in pause (i know i can put a check in each activity, but i want only one sub to manage all). An interesting thing can be this: https://stackoverflow.com/a/44461605/2684 https://developer.android.com/reference/android/arch/lifecycle/ProcessLifecycleOwner Many thanks
Hi to all! Is there a way to know when application goes in background? I want to stop mediaplayer when app goes in pause (i know i can put a check in each activity, but i want only one sub to manage all). An interesting thing can be this: https://stackoverflow.com/a/44461605/2684 https://developer.android.com/reference/android/arch/lifecycle/ProcessLifecycleOwner Many thanks
DonManfred Expert Licensed User Longtime User Oct 12, 2018 #2 create a sub in the starterservice and call this sub from each activity. Upvote 0
Emme Developer Well-Known Member Licensed User Longtime User Oct 12, 2018 #3 DonManfred said: create a sub in the starterservice and call this sub from each activity. Click to expand... Yes but this means that i need to add a sub in each activity. If i have 200 activities, i need 200 sub in activity.pause. I think this is not the best practice to achieve what i want Upvote 0
DonManfred said: create a sub in the starterservice and call this sub from each activity. Click to expand... Yes but this means that i need to add a sub in each activity. If i have 200 activities, i need 200 sub in activity.pause. I think this is not the best practice to achieve what i want
Star-Dust Expert Licensed User Longtime User Oct 12, 2018 #4 You can see if your App is in the foreground with this Library https://www.b4x.com/android/forum/t...d-osstats-and-getforegroundapp.34954/#content Upvote 0
You can see if your App is in the foreground with this Library https://www.b4x.com/android/forum/t...d-osstats-and-getforegroundapp.34954/#content
Emme Developer Well-Known Member Licensed User Longtime User Oct 12, 2018 #5 Star-Dust said: You can see if your App is in the foreground with this Library https://www.b4x.com/android/forum/t...d-osstats-and-getforegroundapp.34954/#content Click to expand... In this case this means that i need a timer that every x seconds check the state of the app, but if i can avoid this solution is a good thing Upvote 0
Star-Dust said: You can see if your App is in the foreground with this Library https://www.b4x.com/android/forum/t...d-osstats-and-getforegroundapp.34954/#content Click to expand... In this case this means that i need a timer that every x seconds check the state of the app, but if i can avoid this solution is a good thing
Star-Dust Expert Licensed User Longtime User Oct 12, 2018 #6 If your App goes in the background it should raise Activity_pause Upvote 0
DonManfred Expert Licensed User Longtime User Oct 12, 2018 #7 Star-Dust said: it should raise Activity_pause Click to expand... it does. But he dont want to add code to his 200 activities to inform the service. I would do it... From my side: good luck to him; i´m out here. Upvote 0
Star-Dust said: it should raise Activity_pause Click to expand... it does. But he dont want to add code to his 200 activities to inform the service. I would do it... From my side: good luck to him; i´m out here.
Star-Dust Expert Licensed User Longtime User Oct 12, 2018 #8 Patience will copy and paste 200 times Upvote 0
LucaMs Expert Licensed User Longtime User Oct 12, 2018 #9 If you declare a MediaPlayer in the Starter service: Code: Copy Sub Process_Globals Public mp As MediaPlayer End Sub in each activity: Code: Copy Sub Activity_Pause (UserClosed As Boolean) Starter.mp.Pause End Sub Code: Copy Sub Activity_Resume Starter.mp.Play End Sub Last edited: Oct 12, 2018 Upvote 0
If you declare a MediaPlayer in the Starter service: Code: Copy Sub Process_Globals Public mp As MediaPlayer End Sub in each activity: Code: Copy Sub Activity_Pause (UserClosed As Boolean) Starter.mp.Pause End Sub Code: Copy Sub Activity_Resume Starter.mp.Play End Sub
Semen Matusovskiy Well-Known Member Licensed User Oct 12, 2018 #10 To write simple program which enumerates all .bas/.b4a files and inserts a line after Activity_Pause, requires 15 minutes maximum Upvote 0
To write simple program which enumerates all .bas/.b4a files and inserts a line after Activity_Pause, requires 15 minutes maximum
LucaMs Expert Licensed User Longtime User Oct 12, 2018 #11 Semen Matusovskiy said: To write simple program which enumerates all .bas/.b4a files and inserts a line after Activity_Pause, requires 15 minutes maximum Click to expand... It would be even easier if you could use Quick Search - Replace With this way: Sub Activity_Pause (UserClosed As Boolean) [special char] line to add where [special char] should be a char for "new line" (CRLF) and you could get: Sub Activity_Pause (UserClosed As Boolean) line to add Also I think that soon we will have the possibility to create activity templates, as it is currently possible with classes. Last edited: Oct 12, 2018 Upvote 0
Semen Matusovskiy said: To write simple program which enumerates all .bas/.b4a files and inserts a line after Activity_Pause, requires 15 minutes maximum Click to expand... It would be even easier if you could use Quick Search - Replace With this way: Sub Activity_Pause (UserClosed As Boolean) [special char] line to add where [special char] should be a char for "new line" (CRLF) and you could get: Sub Activity_Pause (UserClosed As Boolean) line to add Also I think that soon we will have the possibility to create activity templates, as it is currently possible with classes.
Emme Developer Well-Known Member Licensed User Longtime User Oct 12, 2018 #12 Guys thanks for all answers, but the problem is not to waste time to write a sub for each activity. Main problem is that i think is unbelievable that there is not a way to create a single event (so a single exit/entry point) to see the status of the app Last edited: Oct 12, 2018 Upvote 0
Guys thanks for all answers, but the problem is not to waste time to write a sub for each activity. Main problem is that i think is unbelievable that there is not a way to create a single event (so a single exit/entry point) to see the status of the app