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.
Related
I have a situation on my React Native app, where user can start a timer and isRunning and startTime states are stored in the app so that it can display current running time when the app is in foreground even though the user quits the application at some point and opens it again.
Is there a way to show notification icon on status bar when the timer is running, but user has quit the application to indicate that the timer is currently "running" (actually it is not doing any operations on background) on background?
I have encountered some apps that display a silent notification that is not directly closable after I have quit the app, but I haven't seen a situation where status bar notification is present (together with notification) until some condition is met after the app is quit by the user.
Is there a way to achieve this? I am using react-native-push-notification and Firebase to push notifications in my app overall.
React-Native manages only Active and Background/Inactive/Foreground state. When user kill the app. JS engine shuts down.
All you can use is Local Notification and Scheduled Notification. I also have one app in which user set a reminder time. And notification invoke at that specified time.
Using Firebase I guess you need to call api after some specific interval for push notification from server side.
I am not an expert in background services or android development but here is my thought... I believe you could dig in and write some java android code for a background unstoppable service (persistent on app close or background states). You can do this by creating a bridge and using native modules to manage your background services. I came across a great resource on medium that details the process of creating a background service, a broadcast receiver and maintaining Headless instance even when the app is closed or the device restarts.Hope that helps you achieve your goal.
Edit
This ready made package will help you with better. Check it out. You actually don't have to write native android java code at all.
I want my app to silently start in the backgorund, without showing any activity on the screen.
It has a service which needs to perform 2 upload tasks.
I'm learning about service, but all boot-up launch of apps talks about showing the activity.
I need no activity to be shown.
Is that permitted after Oreo?
You didn't say what should trigger your app from background. I presume some kind of an Intent. As far as I know there is no way to start service in the background since android O without showing anything to the user. You should start your service using startForegroundService(), then show notification, perform your 2 uploads and turn off the app (hidding notification too). If those uploads aren't huge, it will be pretty quick, and in most cases user won't even see the notification.
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.
The requirement is for an enterprise application. The application will be started on device boot. It will be running in the background and the user should not be able to disable or Stop the application. In Android a user can go to Settings->Application->Manage Application and stop my application. Is there any way to prevent this from happening?
No there is not. You can prevent Android from stopping the application by utilizing a Service and marking it as a foreground service, though this will require your application to display an icon in the status bar.
You can not make your application live forever, but it depends on what you really want to do. It's possible to receive a lot of events of the mobile and execute code even if your Activity/Service is not running. You can use BroadcastReceivers to look for interesting events and then start a service. I do it for an Enterprise Application that sends an event to a main server when the user has received/made a call.
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