Android App based on a service stop after some time in background - java

I've created an app, based on this link https://www.geeksforgeeks.org/services-in-android-with-example/, for playing an audio file than have 10 hours in background. But, after block or minimize, unfortunately, the sound stops after some time.
Do someone have an idea why this happening? Is there a way that keeps the app playing the sound after block or minimize, just like Spotify does?

I have made a repo for that app. For now, I have not added features to add controls when the app is running but will be coming soon. But, for now, when the app goes in background, the audio starts playing with the following controls:
Start
Pause
Reset
You can find the repo over here.

Related

Uninterrupted background music across all activities in Android Studio game

I am currently working on a game in Android Studio and am having issues with implementing a constant soundtrack across all activities. The way I want it to work is that when the app is started up, an audio file will begin playing and looping and will continue looping throughout all activities, and essentially never end (or restarted when changing activities). At some point I would also add a mute/silent button as well. My question really is, how can I create a class for this sound file to play on repeat upon booting the app and also continue without interruption when changing activities. As it currently stands I have a few lines declaring a Mediaplayer object and setting it to loop and playing it, within each activity.. I realize this is not an efficient implementation but I am brand new to Android Studio and still figuring this out.
Follow this tutorial:
https://www.codeproject.com/Articles/258176/Adding-Background-Music-to-Android-App
And start the Music Service in your MainActivity, if there are still any issues, then let me know.

Stop app from pausing music (from Spotify etc.) on launch?

I'm busy making a template for a general UI which I can use in multiple apps, and I discovered that my app pauses music playing in the background whenever it is launched - most likely due to it having its own start-up sound in the form of a .mp4 that is played as a splash screen.
Is there a way of preventing my app prioritizing its own volume above others or making it mute its own volume when sound is already being played by the device?
PS: If using .mp4 is not general practice for splash screens, I admit, I'm learning as I go - if anyone can correct me on the proper or most optimized solution for making a sound + video happen while not interfering with external apps' sound, that would be much appreciated. Thanks :)
The only way that I know of is disabling the sound for the app that is causing the issue. Most apps have a setting to turn off sound. I don't think you can disable this for every app at once, otherwise when someone calls, you would have to manually turn off the music before answering, "hello".
You can also go into your app settings and "stop notifications" which might help.
I've been using Spotify on my s10 for some times. I also faced the same issue. I found a post why Spotify keeps stopping, and I cleared cache and turned off power saving mode on my device. You can try logging out from other devices which is also helpful

Android: Re-open app after X minutes of idling?

I need my app to open itself back up after a certain amount of minutes that the device has been idle. In other words, instead of the device going into sleep mode and going to a black screen, my app will open back up (assuming it's running in the background). Think of it as an "idle screen" app.
It's fairly simple in theory, but I just can't figure out if it's even possible.
Assuming you have some service running, you can reopen the application by using one of the methods described here Launch an application from another application on Android

how to work with a MediaPlayer perfectly in android

I am working in an online radio streaming project, where I am playing audio with mediaplayer from an URL. The music is playing and working fine. But I am stuck with the play,pause functionality regarding to the state of the player activity. I want such that when the app will be exited by home button press then music will keep playing, but when a phone call rings then the music will be paused and after the phon call the music will resume. And also when user opens another app then the music will continue playing in background. (as the default music player of android works)
But still what I did results almost my desired destiny, but something is missing, like I have started the music in onResume and stopped the music in onDestroy.By doing this the music keeps playing in background when I press home button, but when a phone call comes and recieved it continues playing which creates a disgusting situation, but when another app is turned on then the music goes off. How should I manage the MediaPlayer that will work like what I want? Any suggession?
Note: I am not using any service here, just an AsyncTask class to play the music.
The topic of MediaPlayer as background service is covered in multiple sources such as this one.
http://www.codeproject.com/Articles/258176/Adding-Background-Music-to-Android-App
You can also find this in the Android official documentation here
http://developer.android.com/guide/topics/media/mediaplayer.html
Hope that helps.

Closing application in Android - delay

I programmed a button into my android app that called the finish() method when I click it. But somehow it does not close until after a 5-6 second delay.
I am recording sensor values for a particular movement of the phone. The problem is when there is a delay after I close, it records those unnecessary values and the analysis is messed up.
So any idea why the UI takes so long to respond? I am very new to Android and I can't find this online. I don't do too much computation- as and when sensors change I record the value onto a file in the sdcard memory. Sometimes if I run the program for too long, it just crashes and I don't know why.
Please help! I would also like to know if there's a manual way to kill through the computer? something like Ctrl+C for DOS?
Is there a keyboard shortcut to close a running Android application?
There is no concept in Android of "close a running Android application".
The Esc key in the emulator behaves as the BACK button to (typically) close the current activity.
I have a button that I use to kill the application in my phone and that has a huge delay.
No, you don't.

Categories