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
Related
If my app runs once, service can start and request to server on background. But when app did not run before, service could not start. Is it possible starting service even that app have not runned before.
Actually what I want to do is that phone can send request to server for once without even runned before. When request sended, it will be activation. Later request is not to require.
No, it isn't possible.
When your app is getting installed for the first time OR was force-closed by the user, it is in "inactive" state (meaning no broadcast receivers or alarms will work), and will become active only when the user launches it manually.
See details here
I have an intent service which is continously polling to check if data has been modified in the server. The problem is if the app remains idle for some time , it stops receiving notification. We are suspecting the service has been killed by android.
I think even GCMINTENTSERVICE is also killed by android in some time.
My question is how come gmail / what's app/yahoo mail always sync without foreground notification. Which sync mechanism they are using.
Are you aware of any other app which is always receiving notification even when in background, so that I can check in Google why it is not killed in some time.
Does Google kill gcmintentservice if it has been running for some time in the backgroud.
EDIT: GCMBASEINTENTSERVICE is the service we are planning to implement for push notifications, because with the older polling service the app did not receive notification after some time. This is may be because it was getting killed by android in some time. So with push notifications, the app will always receive notification? Isn't Gcmbaseintentservice an intent service and that will also be killed by android in some time.
Android will kill services after some time, to resolve memory issues. It's not a good thing to always run your application in background, since it will consume memory and processing power.
You have got the wrong idea. GMail and Yahoo are not polling for new mail, they are using Push Notification mechanism, more precisely Google Cloud Messaging or GCM. Push Notifications can be received in the background, and once they receive a push notification, they sync the app.
BBM (BlackBerry messenger) didn't use GCM, as they relied on BlackBerry servers. So they ran the application in the background without getting killed. This is done by always showing non swipeable notification. Someway with notification, you could run a service in background without getting it killed.
According to AndroidHeadlines
You may want to leave it persistent if you want to use BBM. In Android
4.3, Google has begun fighting apps that suck down battery and stay alive without you knowing. It now requires any app that wants to run
in the background to place a persistent icon in your notification.
Hence the BBM icon. Doing this allows that particular app to never be
closed.
Surely google will kill any service if the device runs out of memory or new services are running in background.
I'm developing a messaging application and I need my service to keep running in background even if the application was closed but without showing a notification in navigation bar and start when the phone is started and restart itself when it is closed for any reason, I know this question has been asked before but I can find nothing to do this, I just want it to be like whatsapp or facebook or bbm services, thanks in advance.
I need my service to keep running in background even if the application was closed but without showing a notification in navigation bar and start when the phone is started and restart itself when it is closed for any reason
That is not strictly possible.
You are welcome to return START_STICKY or START_REDELIVER_INTENT from your service's onStartCommand() method. Android will still terminate your process due to old age and low memory conditions from time to time, but Android will eventually restart those services. What percentage of the time your process will be running will depend on a variety of factors, not the least of which being how much system RAM the Android device has.
Better yet, you are welcome to use Google Cloud Messaging (GCM) to deliver your messages to your app. This way, you do not need a service running all of the time. Your app can get control when a message arrives, do some work for that message, then go away.
I just want it to be like whatsapp or facebook or bbm services
BlackBerry Messenger uses startForeground() and has an icon in the status bar as a result.
I'm developing an application that uses a Bound Service to query information from a server and provide notifications when conditions are met. At the moment, the user must execute the application from their home screen in order to begin receiving updates. But, for example, applications like the Facebook Messenger and Llama run from the moment the phone starts in the background. How do I achieve similar functionality for my long-term application? Also, even when my application is run from the home screen, it will still ocationally quit in the background from what I assume to be the system quitting the application for additional resources. Even though my application is made to restore the service when it begins again, it never seems to restart after it quits (usually after 3 to 4 hours of background activity).
Thanks for your help.
You can register a BroadcastReceiver for the ACTION_BOOT_COMPLETED Intent to detect when the device is booted. This requires the RECEIVE_BOOT_COMPLETED permission.
Instead of using a bound Service you can use a started sticky Service. However, depending on what exactly you want to do, you might want to check if AlarmManager suits your requirements better (maybe in combination with an IntentService, cf. cwac-wakeful).
I'd like to know if it's possible to send a local notification to the device when the app have been opened then closed.
It works already when my app is opened and when it's in the background.
Thanks
Edit : I think i wasn't clear enough:
I want to send a local notification at a given time even if the app is not running at that time.
By "Local Notification" i mean a Notification (android class) created in my app and send by using an AlarmManager and a BroadcastReceiver.
closed -> killed the process of my app
Most means of "killed the process of [your] app" will leave your alarms intact, and so whatever you have scheduled will remain scheduled and keep being invoked as you set up.
I want to send a local notification at a given time even if the app is not running at that time.
Again, AlarmManager is not dependent upon your process being around, so long as it can invoke the PendingIntent that you supply. So long as the BroadcastReceiver you are using is registered in the manifest (and not via registerReceiver()), it should work fine.
If the user force-stops your app -- usually via the Settings app -- then not only will your alarms not be invoked, but your code will never run again, until something explicitly starts up your app (usually the user tapping on your icon in the launcher). There is nothing that you can do about this.
it's hard to explain things when you do understand fully and when english is not your native language
There are many Android developer support sites, offering a variety of languages.
you need to create a service, http://developer.android.com/guide/components/services.html