My application uses a remote service to play audio. I do this so that no activity owns the playback of the audio - the user can trigger some audio to be played from one Activity, and the audio will continue to play as they navigate around the app. I do, however, want to tell the service to pause or stop playing audio when the user "unloads" the app either by backing out, locking the display, or hitting Home. When the app was a single activity, I was doing this in onPause. So, I guess I'm essentially looking for "onPause" at the application/task level. Does such thing exist? If not, what is the "best practice" way of getting notified that the task has been put on hold by the user either backing all the way out or hitting Home?
Android: Task or application equivalent of onPause
1k Views Asked by Rich At
2
There are 2 best solutions below
Related Questions in ANDROID
- Creating global Class holder
- Flutter + Dart: Editing name of a tab shows up a black screen
- android-pdf-viewer Received status code 401 from server: Unauthorized
- Sdk 34 WRITE_EXTERNAL_STORAGE not working
- ussd reader in Recket Native module
- Incorrect display of LinearGradientBrush in IOS
- The Binary Version Of its metadata is 1.8.0, expected Version is 1.6.0 build error
- I can't make TextInput to auto expand properly in Android
- Creating multiple instances of a class with different initializing values in Flutter
- How to create a lottie animation
- making android analyze with coverity sast tool
- Flutter plugin development android src not opening after opening example
- I initialize my ViewModel in the Activity with several fragments as tabs, but the fragments(tabs) return null for the updated livedata
- Node.js Server + Socket.IO + Android Mobile Applicatoin XHR Polling Error...?
- How I can use the shared preferences class?
Related Questions in AIDL
- Share the surface between different apps with AIDL in Android
- onServiceConnected not called but context#bindService return true
- How can a C++ client bind to AIDL service on Android?
- IPC between Android app and native user space process
- How to implement AIDL on openvpn flutter project?
- AIDL (Android Interface Definition Language) in android studio
- android 12 + aidl + hal server + app client
- How to intercept messages between services in Android which interact via IBinder using AIDL?
- Doxygen cannot include .aidl interfaces and enums to the documentation
- Unable to import AIDL
- How to import Surface for AIDL?
- How do I define a custom class with Parcelable using Stable AIDL?
- AIDL based HAL cannot generate java
- when i use kotlin-parcelize in my application,after i build my project ,i get a error : can't find symbol readFromParcel
- AIDL service is not working in Android 13
Related Questions in APPLICATION-LIFECYCLE
- On Bean destroy invoking Pre-Destroy method or Listening to ContextStopped or ContextClossed event is not working
- Application is reboot when revoking application permissions
- Angular2: Are dynamically created injectors (created via Injector.create(...)) ever destroyed?
- App Foreground callback coming late in IOS swift
- Why my app gets fired immediately after entering background mode?
- signalr method not being triggered in onSleep event xamarin.forms
- How to automatically remove a Kubernetes pod when it does not receive TCP/UDP connections for a certain period of time?
- How do "Suspended" and "Not Running" states look like for the user?
- Animation library is giving me this error about lifecycle state
- Flutter: Common class to whole check whole app lifecycle
- LifecycleObserver.onCreate is not called when Application is created
- WindowsAppSDK doesnt have ProtocolActivatedEventArgs
- How can I detect If my android application is Destroyed/Paused/Stopped without fail?
- Why is (and how to fix) my Android application triggering an onCreate (ON_CREATE) when removed from memory?
- Lifecycle @OnLifecycleEvent() is deprecated, and you should use LifecycleEventObserver or DefaultLifecycleObserver
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Hmmmm...unfortunately, I suspect there's no easy answer there. I think that's why the built-in media player and Pandora use a notification, to easily let the user get back to the app to make it shut up.
If your activity flow is fairly linear, then backing out of the application is the same as backing out of the initial activity.
A trick I used in one scenario was to have each activity notify the service in
onPause()andonResume(). The service would monitor these, and if it got anonPause()without a subsequentonResume()in some period of time, it was assumed the user was gone (HOME, incoming phone call, incoming text message, responding to some app via a notification, etc.).You can also watch for
ACTION_SCREEN_OFFbroadcastIntents, to handle that scenario.I am sorry that I don't have a better silver bullet answer -- perhaps somebody else will have a better idea.