Android Alarm Manager not being triggered - android

I have my app installed in 2000 devices. In most of them it is working great. But some users (maybe 100) report me that the app is not updating correctly.
I found out that the problem is that the AlarmManager is not triggering an Alarm. The app is supposed to update data every 15 minutes so I use an Alarm Manager for that.
With no reason, it seems like it stops working after a while of running and it never starts again unless the phone is rebooted. Then it works again for a while and finishes stopping, too.
I don't have access to those devices but the users tell me they don't have any task manager or background cleaners. And in case they have them, then my app is in the 'ignore list'.
I have tried to emulate this scenario but I cannot.
It seems like the app is killed and the alarm managers don't work. By the way, those killed apps don't receive GCM events either.
So the questions are:
Is there anyway to prevent the app from being killed or to ensure the alarm is triggered at the time I set.
Can I use broadcast events like Screen-on, Screen-Off or Telephony incoming events to check if the alarm has been triggered and in case it is not to do it at that moment? I am not sure if this would work because if my app is killed then probably it will not receive any event, correct?

Related

App AlarmManager not working after clearing App Data

I wish to show a status bar notification at 12 pm everyday and hence, I'm creating an AlarmManager which fires an IntentService which will show some notification.
I've added Boot completed receiver and the AlarmManager is registered when the app gets lauched. Everything is working fine and the Notifications are shown everyday at 12 pm even when app is not in foreground (expected behaviour).
The problem is, whenever I clear the App data in Application settings, The AlarmManager no longer triggers the Application notifications. However, When I launch the app again, the App starts working with the notifications everyday with an expected behaviour.
Could anyone please help me with this issue? Is there a workaround to ensure that AlarmManager is triggered irrespective of these conditions.
Is there a workaround to ensure that AlarmManager is triggered irrespective of these conditions?
No. When you press 'Clear data', not only is the app's data cleared, its processes are also killed. When that happens, scheduled alarms are killed with it.
It's not strange that this happens. A running app might need data that you cleared, if it doesn't find that data, it could crash. Killing the app will prevent those crashes.
This is normal behaviour. If the user voluntarily force stops or clears the data of the application,then it should be stopped. android system kills the entire task ,No services or broadcasts are allowed to run until an activity is run again. so you can't do anything to prevent this. see the qn answered here.

Is the Intent.ACTION_TIME_TICK intent broadcasted on a Lollipop Android device while the device is sleeping?

I'm building an Android app that requires me to send messages to another device via Bluetooth every minute while the phone is sleeping.
This requires me to register a receiver that listens for the Intent.ACTION_TIME_TICK intent when the app calls onStop() and unregister it when the app calls either onRestart() or onDestroy().
This worked when my phone was on Android Kitkat, but now that I've updated the OS to Lollipop, Intent.ACTION_TIME_TICK does not seem to be broadcasted every minute anymore. In other words, Intent.ACTION_TIME_TICK is not consistently issued by the system while the phone is sleeping during Android Lollipop (even though it did work for Kitkat). Therefore, my broadcast receiver listening for this intent is triggered at weird times (sometimes never triggered, sometimes triggered in the middle of a minute).
Is this purposeful or is this an Android bug in the Lollipop OS? Is this in any way related to the fact that the AlarmManager API also does not have exact time deliveries from API 19 now due to the new batch policy that minimizes battery use by "batching" alarms together (http://developer.android.com/reference/android/app/AlarmManager.html)?
Most importantly, is there any way around this so that I can still receive updates when the time has changed? Note: I do not want to use the AlarmManager API.
Thanks in advance!! All help is appreciated.

Android BOOT_COMPLETED

I have a question concerning the BOOT_COMPLETED event.
I need a service to be running at all time (done via AlarmManager) but I wonder if I have to start the service manually the first time the application is installed as the BOOT_COMPLETED event is sent only after the device is restarted. How is this commonly handled, it seems like no one is having this problem, am I getting something wrong here?
the user should be the one deciding on if the service is running or not when its first installed and not you, so yes it should be started manually when they launch the app for the first time

Scheduling Android Service to Run & Restart if Closed

I'm trying to implement an App that will perform a periodic sync w/ server, lets say ever 30 min. I have been successfully able to implement this using a Receiver & Service triggered via AlarmManager, however the downside is that if the App is closed through TaskMgr the alarm dies with it.
I understand that this is expected behavior for Android OS, however I noticed that some Apps like Facebook have a service that starts back up after a short timeout even if the Facebook App was closed in TaskMgr. I monitored this and see the service disappear and re-start after about a minute or so. There's a number of Apps that behave in similar fashion (Twitter, Dictionary, ReadItLater, etc)
I would like to reproduce this behavior. This way even if the user closes my App in TaskMgr by mistake they can still have periodic sync run in the background.
Thanks in advance.
There should be an inbound process associated with the service if it needs to be restarted even after cloasing using task killers.YOu can achieve this by displaying an ongoing notification at notification area as long as service exists and by launching service via startForeground()
http://www.androiddiscuss.com/1-android-discuss/91804.html
please check the link

Executing code when Application is updated/reinstalled

I have Some Alarms set via AlarmManager to do some periodic jobs.
I set/reset them when user opens the app for the first time & on every boot_complete event.
But when the app is reinstalled via ADB then my alarms do not fire anymore. looks like the OS deletes the Alarms on reinstall of the app. I assume this will happen if the user updates the app from the market also.
If I can receive a broadcast or some sort of callback in the event of reinstall/upgrade etc of my application, I can set the alarms again. but i don't know if it is possible or how?
Can someone please help me out.
Yes, this is possible.
You can create a broadcast receiver that listens for any PACKAGE_* events the system sends, but you won't receive them for your own application except for when your application is being upgraded — you'll get PACKAGE_REMOVED followed soon after by PACKAGE_REPLACED.

Categories

Resources