keep my app waiting for phone calls - android

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).

Related

Android and background processes

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.

How to keep listening the S Pen detachment after the app gets closed from the Recent Apps list?

The goal is simple: to start an app when S Pen is detached. It is clear that it should be a service running even when the app is not running. This answer provides a good example of how to create a service to listen S Pen detachment by registering a receiver with BOOT_COMPLETED action. It does not matter whether you start your service from the app activity, or by registering a receiver - it works fine if you just "close" the app using Back button. But if you go to the list of recent apps and clear the app out of the list - the service stops and it does not work until you restart the device again. Does anyone have an idea how to keep listening the S Pen detachment even after the app was cleared out of the Recent Apps list?
Register a Broadcast Receiver for com.samsung.pen.INSERT as described in this answer: Bring your app to the front when S Pen detached in android note?

Android service that was running when the phone was shut down starts automatically when the phone is booted

I am currently developing an Android telephony application that includes a service to handle all the SIP signaling for making and receiving calls.
I want this service to start exclusively when the user has correctly logged into the application. However, I am observing an undesired behavior: if the device is shut down while the app is running, the service is automatically started after the phone boots. This does not happen if the application is closed at the moment of shutting down the phone.
I have been reading about it but no answer comes up. Could anybody explain why this happens and how to prevent it?
Thank you in advance.
Thanks to CommonsWare comment I have quickly found the answer:
[...] The only way a service starts up is if somebody starts it, and the OS will not do that on its own.
I was so blinded thinking the OS was responsible for it that I didn't notice it was being done on purpose, as an undocumented feature inherited from a former version of the app.
There was a BroadcastReceiver listening to the android.intent.action.BOOT_COMPLETED action. This receiver was, among other things, restarting the service on start up when the app had not been properly shut down.
Thank you CommonsWare for your help.
Update
After preventing the BroadcastReceiver from listening to the BOOT_COMPLETE action, I still experience the same behavior.
The reason is that this BroadcastReceiver is also listening to connectivity changes to restart the SIP service when the WIFI or a data connection becomes active, only when the app is running. Wether the application was closed or not is stored in the app preferences, but this value was not properly set when the phone was shut down while the app was running.
That is why the service was still unwantedly starting on boot: because the BroadcastReceiver detected an android.net.conn.CONNECTIVITY_CHANGE at start up and the preference telling wether the app was still running or had been quit was not properly updated.

how to make server call whenever device screen is turned ON without Service

This requirement is only satisfied if the app is running in the background.And if the Screen is turned on if the user presses to check any notifications then an Asynctask is called if the app is running in the background and makes a call to the server.
I have tried using Broadcast Receiver when screen on and tried to execute, it works only if the app is on the front screen after pressing the home button .And then if the user presses Power button after an hour then nothing happens .
Basically I am not sure if the app is being killed after sometime when in background. Please help me.I am a noob in Android and this functionality is something I thought most of the developers might be using but I did not see anything except service calls and I really did not want any service/alarm-manager as I don't want it to work continuously.
TIA
how to make server call whenever device screen is turned ON without Service
This is not possible. ACTION_SCREEN_ON is a broadcast that can only be received by a BroadcastReceiver registered via registerReceiver(). So, unless you are the foreground activity, the only way you can receive this broadcast is via an always-running service, which is not a good idea.
as I don't want it to work continuously
Then do not "make server call whenever device screen is turned ON". Find some other solution for whatever business problem you have that you are trying to solve this way.

Can I prevent the user from stopping my Android application?

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.

Categories

Resources