I have an app which consists of a simple GUI and a few Broadcast receivers.
I found somewhere on here how to start an app on boot of the device but cant seem to locate it atm.
However i need more i need it to start in the background and just listen using the broadcast receivers and then return to this state after the Gui(the visible part of the app) has been used.
Is there a way of doing this?
Thanks.
Look into the Service class. Services run in the background and have no direct user interaction.
http://developer.android.com/reference/android/app/Service.html
Related
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 am making an Android app which is supposed to monitor the other running apps.
The question is, how do I make my app run continuously from when i first activate it. It should also start running by itself when I switch off and reboot the phone.
Any suggestions on how to ensure this? I am considering using a background thread but I am not convinced this alone will suffice.
You should make an android service that running continuusly in background
http://developer.android.com/guide/components/services.html
http://www.vogella.com/tutorials/AndroidServices/article.html
http://www.tutorialspoint.com/android/android_services.htm
Well you should try to have an Service into your app that could keep track of the other App's running
So Every Time the App start's the Service Would Start And Accordingly give The Updated to your app regarding the Other App Working
For Boot Time Start you Should Try System BroadCast Receiver
You should Really Follow this Tutorial
Create a service to monitor apps in the background.
http://developer.android.com/guide/components/services.html
To make the app load at boot:
Create a BroadcastReceiver and register it to receive ACTION_BOOT_COMPLETED. You also need RECEIVE_BOOT_COMPLETED permission.
Refer to this:
Android -Starting Service at Boot Time
You have to use a Service. But keep in mind that your service can be killed and restarted after a while.
And you should register a broadcast receiver to listen for ACTION_BOOT_COMPLETED so that you can start the service once the phone booted successfully.
I have a very hard time to finding real solution.I searched a lot but I cant find any good solution for my problem.
I want to perform some action when user click on notification.So I have to check whether application in background or foreground. If it is in foreground then which activity is running ? There must be simple way to find this.
Please Guide me on this.Any help will be appreciated.
You should listen in two places of your application:
In your activity to show the alert.
In your service to show the notification check if activity is running using one of following solutions.
You have severals answers there summarizing the solutions:
Android: how do I check if activity is running?
Checking if an Android application is running in the background
Because If application is in background then show notification otherwise show alert.
Then you do not care "whether application in background or foreground" or "If it is in foreground then which activity is running".
You simply care that, when the event occurs, either the foreground UI handles it (if there is a foreground UI), or else you show a Notification.
One approach is to use an ordered broadcast, as I blogged about a couple of years ago. Here is a sample app that demonstrates this. Basically, the service(?) sends an ordered broadcast. The UI has a high-priority receiver for that broadcast when it is in the foreground, and it aborts the broadcast and consume the event. You also have a low-priority receiver, one that will only get control if the UI did not consume the event, that will display the Notification.
I am going to implement Download Queue for my application. One of its feature will be when Network get connected or disconnected. I want to notify my QueueManger(Service) to update items status and stop.
I know use of Broadcast Receiver and how to use it. My question is if my application is stooped (finished) will broadcast receiver will work? Will it notify application or not?
If not is there any way to achieve this functionality even when application is stooped.
If you register your receiver in the XML instead of programmatically, then it should be able to catch these even when the program is not running.
See question, same solution applies Intent action for network events in android sdk
If you have defined your broadcast receiver as <receiver> in AndroidManifest.xml and listening for android's default action strings, then Yes, it will work.
Otherwise, I would recommend you to make use of Service. It can run silently in the background and do all the logic you want. Your service can even be provoked automatically when the phone is restarted (if you code correctly).
I'm building an app that collects info about the battery (using background service).
I want this service to start running from the moment I turn on the phone, How do I do it?
On the other hand I want to activate the GUI (interface) of the app only when the user clicks on the app. The app and the background service are in the same project.
Is this the correct way to do what I want?
That is the correct way to do it: see http://www.tutorialforandroid.com/2009/07/permissions-journey-receivebootcomplete.html for info about listening for the BOOT_COMPLETED Intent. You can start your Service in the BroadcastReceiver and then bind to it in you Activity.