I wrote an bluetooth app with my bt-connection established in a service, so the connection is still alive when I minimize my app.
But when watching my task manager, my app is still there.
And when calling onDestroy in my app, I have to stop my Service.
But other apps like telegram or skype (whatsapp too I think) aren't in my task-manager visible but by having an incoming message they notify me nevertheless.
How is this even possible? How can I write my bluetooth connection like this, that I can really close my app and anyway the incoming messages will be handled?
The other apps might be having some light weight service running in other process which gets the data for the main app.Go to settings->application manager->running processes..you will see all the service..
Other mechanism which apps use is port-directed sms. In such a scenario you don't need any service running.However port directed sms doesnt work on all the phone and for all the apps.
When you put remove your application from the foreground, Android keeps the activity on the stack again in case you will go back to it (unless you explicitly destroy the activity). So this maybe one reason why you still see it in the Task Manager.
You cannot kill entirely the app and it will still post messages. Your service will be running in the background and it will be visible in the app Manager->Running Services.
However if you destroy your activities the app it will not be visible in the app list of the Task Manager.
Related
I have a service, which monitors a server for changes.
When I open the app and just press my home button to leave it, all works fine.
But when I kill the app from the "recent apps" view, I don't get any notifications anymore.
I know that there is way, to use startForeground. But then I have to display a notification.
But how does the stackoverflow app work? There is no notification, no entry in the android account manager or anywhere else. But without starting it and without keeping it in the recent view, I get notifications for new answers.
How does it work?
Try to start service in another process. This way even if you kill your app through "recent apps", the other process (in which the service runs) will continue running. Also, on the onStartCommand of service, return START_STICKY. This will tell the OS, if for any reason you need to close the service run it again when you have enough resources.
Sorry I do not have enough reputation to put it as comment.
I have an android app which waits for incoming calls to arrive and then (when the call state changes (I'm using the telephony manager class to detect incoming calls and its working great)) my app does something.
The problem is, if my app is running and listening for calls in the background, and then I open some other heavy apps and using them massively, my app gets paused by the system and the user must re-open it in order to resume listening for phone calls.
Is there a way to keep my app waiting for calls as long as the user didn't press on the "stop listening" button inside my app ?
Thanks.
Maybe this wil help you ,i had the same thing and i solved it with this answer
Use Broadcast Receiver to receive telephony broadcasts, which you have to register in a background Service. This way, the system will automatically notify your app about the events and also restart the app if it's not already running (of course, it won't happen if the app was force closed).
Let's say I started a repeating background service that was stated on first app launch and on boot. What happens when I provide an update of the app. Will that background service be killed?
Will user have to open the app again to register the background service again or app will get some callback on update?
Edit-1: As one of the answer suggest if app has to be relaunched again to start the service then how does alarm application works fine after the update without relaunching(I believe it usages background service to start the alarm)?
Will that background service be killed?
It will be killed.
Will user have to open the app again to register the background service again or app will get some callback on update?
It depends. Basically it'd require user activity as app is not relaunched automatically after update. But if you target API 12 or higher (which you should nowadays) you can try to use ACTION_MY_PACKAGE_REPLACED broadcast. As per doc:
Broadcast Action: A new version of your application has been installed over an existing one. This is only sent to the application
that was replaced. It does not contain any additional data; to receive
it, just use an intent filter for this action.
so you can do you stuff either in BroadcastReceiver trigger something once you receive this broadcast.
The service will be killed and needs to started again.
A Service doesnt run on a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.
So when the application is updated, the application is sent to the stopped state.
You can test this.
From google play store initiate a update for the app (which has a service E.g Whatsapp).
Open the app and wait for it to complete. It stops. you can check the internal running processes. Connect the phone to DDMS. Check the processes.
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).
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.