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.
Related
I don't understand why my rootSaga continues to run after my android onDestroy was called.
When using the app if I do config changes like font-size, screen rotation etc ...
android onDestroy will be called (I still see app in recent apps which is also weird).
The app will open but everything will be stuck because my rootSaga is not being restarted and will continue from the place where it was before
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).
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.
I have written an app using background service, which is launching on specify time. I'm using WakeLocker (CPU only) and for the time I use Handler with delay. During the tests on HTC everything works fine but on Samsung Galaxy S2 everything is weird. Base functionality doesn't work and if service is already active and user run three different apps (not after one, not after two, always after three!!!) My activity is being restarted and doesn't see running service... Why???
I Have developed an application which contains many activity.
I have noticed an issue while one activity starts another activity and meanwhile if we press camera button or get a call my application hangs and never recovers even after ending the call or closing the camera.
Basically what I want to know is how to handle external interrupts(alarms, calls, camera) so that my app resumes from where it had stopped.
I am replicating this issues on emulator as well as on LG Device.Can anyone give me some idea to how to handle onpause and onrsume function call in this case.
Thanks