I am wildly confused with the current Android background service possibilities and need some help from an expert :)
The "xDrip" application is broadcasting its information via an (I guess implicit) intent with the action name "com.eveningoutpost.dexdrip.BgEstimate". I want to receive these intents. As it is not allowed to put them into the manifest I registered them dynamically in the onCreate() method of my application class. This is working great as long as the app is running (even when the app is not open on screen). But if I swipe it away in the app overview, it does not receive the intents any more even though I do not unregister the intent.
My question is now: What would be the most suitable way to receive this (implicit) intent reliably all the time? So also when the user swipes the app away in the app overview screen?
Cheers!
This is working great as long as the app is running (even when the app is not open on screen).
More precisely, this is working great so long as your process is running.
But if I swipe it away in the app overview, it does not receive the intents any more even though I do not unregister the intent.
More precisely, you stop receiving the broadcasts once your process stops running. Note that this will happen naturally while you are in the background, even without a manual swipe of your app off of the overview screen.
What would be the most suitable way to receive this (implicit) intent reliably all the time?
Technically, it's impossible.
You will get close if you use a foreground service, to keep your process around longer. However:
The user can still swipe the app off the overview screen, and this might still stop your service and terminate your process
Even a process with a foreground service might be terminated by Android automatically after a substantial period of time
Your app will be consuming system RAM the entire time, which users may or may not appreciate
Related
Basically, we've got a bunch of sdks and whatnot that start up in the app's oncreate code.
However, even if the app is force closed, android will boot up the oncreate just to show a push notification.
I'm trying to switch code paths based on whether or not the app was actually launched or if the app was just kicked awake by a service or receiver.
While I know I can use the intents for this, because it happens in a background, I can't actually get an intent from an activity to determine this.
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 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.
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.
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.