Android Background Service Working at Emulator but not at phone - android

I developed an android application that starts an android background service. This service sets alarms on the selected time instances. This application and the service is working absolutely fine on android emulator. Works as I expected it to. But the strange thing happens when I installed this application at my android phone. The application worked fine, it started the android service too. But nothing happened from there on. I checked the settings-apps-running apps at my phone. It showed that the service is running on phone. But the thing that I expected from the service was to ring alarms at selected time instances, which it didn't at my phone. I have a samsung galaxy nexus phone. Can you please diagnose what is the problem actually?

Related

how the apps like whatsapp is running as the background service which are not killed by the android system

how the background services in whatsapp, facebook, instagram are running even if the app is closed in android versions >=N. also please suggest how to approach this problem
I am trying to get the current GPS location and update in server as a background service
(Note : I am using Gionee-X1 (Android-N), MI-MA4 (Android-N))
I have tried Foreground notification which is killed after 5 to 10 minutes in Gionee mobile and instantly in MI mobiles,
Also tried Ignore Battery optimization worked partially in some mobiles and not worked in MI Mobiles
Tried alaram manager, not working properly after the app is cleared
Tried Work Manager, PeriodicRequests is not working, OneTimeRequests with delay is worked upt 10 minutes in Gionee Mobile (When i configured periodic requests, it executed nearly 6 times within a second and not executed after that)
Finally, I need a piece of code or a procedure which should run a background service (also foreground service) and not to be killed by system when the app is closed or cleared from background.Also please tell how to implement service has to be restarted if system kills the service
Need to disable "Battery Saver" process, to run your app continously .. In MI (My version is Redmi Note 8 Pro), navigate to Settings->Apps->Manage Apps->(select your app)->Battery Saver->(then set "No Restrictions")..

Android 4.3: App spawns many processes on sync

On the Samsung S3 with Android 4.3, my Android app spawns new processes on every sync request using the SyncAdapter. The processes survive the "Force stop" button in the system's app settings and even an uninstall of the app. Only after a reboot, the processes are gone.
On an Android 4.3 simulator, this behavior is not reproducible.
On regular devices, our app is running in two processes (one for the app and one foreground service).
Has anyone heard of this beavior before? Might be a Samsung-specific issue. We have never seen this behavior on any other Android device.

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.

How to auto restart a service when killed?

I have already red many posts about the subject, some of these works, but only on some devices. For example it works on my Nexus 4, Nexus 5 with cyaogenmod, but not on my Xiaomi Mi2s (jelly beam 4.1.1)
I tried setting it sticky, using alarm, and broadcast receiver on destroy. But neither of them worked out. When I kill the application it never wake up again. But on the same device Whatsapp works perfectly, and even if I kill it, it wake up again..
Is there any way to do it without use GCM?
Some of the link I already looked up:
How to restart a killed service automatically?
Service that repeatedly runs a method, after an amount of time
https://stackoverflow.com/a/21551045/627307
I'm not sure if it will solve the issue for you or not but it worked for me.
I'm running MIUI 6.6.10
Open the Security app provided by Xiaomi
Click on permissions -> Autostart
Here allow your app to auto start
WhatsApp and all famous apps work because Xiaomi white listed them and allowed them to autostart.

Why android always kills my app after three different processes?

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???

Categories

Resources