Service stopping after some time Android 10 - android

I'm trying to create service that plays music in background. Everything works fine, except that the service is stopping after some time when the phone is locked. To be exact - my service logic looks like that:
after pressing start it plays music (playNext function is called), when the music ends the playNext function is called again. For some time it works perfectly, but when the phone is locked after a few songs, the song is ending and the next one is not starting until I press any physical button to wake up the phone.
The service is being run in foreground with a Notification, onStartCommand returns START_STICKY.
I'm using Android 10, my phone is Xiaomi Mi A2 lite.
As far as I remember issues like that weren't happening to me before - is it some new 'feature' in Android10 to workaround? And how to do that if yes? Or maybe it's my phone model problem and nothing can be done here?

It seems I have found a reason.
The problem is with my phone. After upgrade to android 10 there are some bugs (for example different music players are spontaneously pausing music).

Related

Android Studio Secondary Activity Closes and Launches with no Audio Service

I have an activity that launches on Button click and an audio service using MediaPlayer is started on onResume for the new activity. The audio service is stopped in the onPause method.
For some reason the activity's audio service does not start. Using log, it shows me that the new activity runs through the onCreate, onResume, onPause and onDestroy methods once before it is created again and stops at onResume, but without starting the audio service.
This only happens on some devices and emulators while it is working fine for others. As an example, it works fine on the emulator Pixel API 23, while it does not for Pixel C API 23. I have two friends who tried running my app on their physical phones, both of the same Samsung model. It works for one of them while it does not for the other. logcat shows no errors when testing on the emulator.
Does anyone have a suggestion as to what could be causing this error?
I have tried android:largeHeap="true" in case it was a heap problem, but to no avail. minSDKVersion is set to 15.

Android service is not working onDestroy

My Android service is not working when the application gets destroyed in Xiaomi devices, but it works perfectly with Motorola devices. Currently I have tested my app with Motorola G 2nd generation, Redmi Note 3 and Mi Pad.
I want to play music in the background when my app is not in recents.
Intent i = new Intent(CollapsingToolbarActivity.this, SongService.class);
startService(i);
well, i got your point, may be u are missing with permission in security app of xiaomi devices. you must allow your app to autostart. that will prevent your service from destroying.
#K. Gandhi He is not saying the app is destroying when using xiaomi device, he says that onDestroy(); seems not working on xiaomi device.
#meeta mastani You have to be clear on your question, but as I understand your question, You are using ForegroundService that you want to run your app even when onDestoy(); is being called or the app is closed.
Answer:
Maybe you are using heavy work on your thread, you have to consider using asyncTask, BackgroundThread, BackgroundService and ForegroundService.
asyncTask - for network operations (internet).
BackgroundThread - for heavy work, but when phone sleeps or displays
turned off, your app will not run or music will not play if you are
making music app.
BackgroundService - your app is in the background but still active
(minimize)
ForegroundService - you app is close or destroy but still working or
playing music.

Is there a faster way to call a receiver than on boot completed?

some context:
I have an alarm app I use for myself that locks the screen when the alarm goes off for the duration you request prior. Essentially your phone is a ringing brick for x minutes. The only problem is my sleepy self is very irrational and in the morning I figured out that if I turn off the phone and get to the app location and uninstall it before the receiver gets called (boot completed) then I can bypass it bricking my phone. This didn't use to be a big deal when my LG G2 was on 4.2.2 because of how fast the receiver was called I would usually have to restart my phone about 5-8 times to uninstall the app before it was bricked so I just gave up and quit trying. Now, I upgraded to 4.4.2 and the receiver is called about a full 10 seconds later letting me delete the app on the first try every time. Making the app completely useless.
What I have tried:
I have tried using quick_boot in the manifest but I believe that this is only for HTC because on_boot doesn't get called for that OS for some reason. I have also tried the user present which only seems to work after the boot is completed when doing things like unlocking your phone.
Is there really no way to make onReceive be called quicker than onBoot? It would make sense if there isn't , I'm just hoping someone could provide a definite answer either way.
In some cases it is. I'm not 100% sure but i think (some) systemapps have higher priority then the ACTION_BOOT_COMPLETED event. AND there is ACTION_SCREEN_ON which should be triggered before ACTION_BOOT_COMPLETED.
I should have answered this a week or so after I asked this question because I found a pretty useful workaround, although, it is a little sloppy.
I made a new activity(homeLock) with the intent filter . homeLock extends activity and my old main activity(alarmMain) extends homeLock now instead of activity. All homeLock does is start the overlay service(so you can't stop the alarm/use the phone) that will be turned off by alarmMain when it determines whether an alarm should be ringing currently or not. In alarmMain there is a button now that says "change home" which lets you make homeLock the home application. Now, when you turn off the phone and restart to try and delete the application before onBootReceived is called which starts the broadcast receiver(triggers alarm and overlay) the homeLock activity is called which puts an overlay on the screen until it can be removed after the application determines if an alarm should be playing or not (after onBootReceived).
Basically, before you go to sleep just set this application as your home application from within the app or through settings. Now, it should be impossible to delete the application or turn off the alarm once it has started ringing until it has rung its duration because there will always be an overlay on the screen even when restarting the phone.
Obviously this addition is only needed for phones that boot slowly or extremely degenerate sleepers, or both like me. While it is unlikely this will help anyone because it is such a unique problem I thought I should post the workaround I have been using just in case someone does end up finding it useful.

android phonegap timer in service plugin stops when device sleeps unplugged

the last couple of days i was busy getting a service up and running for an phone gap application (using the eclipse ide with the device (motorola defy android 2.3.) connected to my computer)/ the service runs in the background when the application is off and has a timer scheduled that passes an intent to launch my application at irregular times/ everything is working as intended/ when the application is off and the device sleeps (screen is black) the timer is still running and at the scheduled time the device gets woken up, the lock removed and the app starts/ however, the bummer came when i unplugged my device from my computer/ the timer seems to work only reliable in sleepmode when the device is connected to my computer/ when its not connected to my computer the timer only fires correctly when the screen is on/ when it is not on it fires unpredictable at will and more often not at all/ i switched off the option that the device should not go in deep sleep when charging/ but it still works when the device is either connected to a power outlet or computer
can anyone try to explain what the reason might be?
is there anything i can do to make sure the timer is running as is should unplugged while the device is sleeping
Sorry my bad, it doesn't FULLY answer your question
One way is to register for ACTION_SCREEN_OFF and ACTION_SCREEN_ON event at the native level and propagate that event to phonegap layer (# html/js level).
More details on handling Screen Off and On intent click here.
More on how to Notify UI layer click here.

HTC one - app is killed every time

Hi I got a problem with my app. App is tracking the user road by GPS. It getting only start point and with each next point calculate distance and increase time. Everything is working great on my HTC Wildfire (with CMD7 2.3.7), Samsung SIII and Galaxy Tab 10.1.
When user start tracking, the app is finishing current activity and start new process with service in background. In the same time start new activity with small animation and put ongoing status in notification area. Everything cool, but problem starts the user is trying app on HTC one series. I can't describle how it behave, cause I don't have this phone and can't reproduce the bug.
Any of you heard anything about memory managing in HTC sense? I read some article that HTC one has this kind a feature.
Or it there is any way to test particular device on emulator?
Thanks for any help.
Make sure you are calling the Service#startForeground method to give your Service foreground scheduling priority. You can find it documented on the Service class:
http://developer.android.com/reference/android/app/Service.html
I have seen background services not get killed by using this on the One series.

Categories

Resources