I want to create a service for my wearable that runs in background that will detect a Bluetooth device. I have written code that is able to detect the Bluetooth device but it uses Activity - onCreate() method to start scanning.
I read many articles on the internet about writing services that runs in background but in every example the service is started from the Activity. I want my service to be running without starting from any Activity. Is this possible? I mean when I install my app is it possible for the service to start running automatically?
Seems like there is no way of starting a service without starting the Activity. I got the answer from there How to start android service on installation
Related
Is it possible to start a service without starting an activity? My plan is to write an application which shows a notification when Bluetooth device is connected and a headset
Thanks for answers
Services ONLY can be started from Android components , such as Activity , BroadcastReceiver and either from another service. Anyway to start a service you need a Context , Because you're gonna call Context.startService(i).
In your case I suggest you to start your service from a BroadcastReceiver as same as this one :
How to detect when a user plugs headset on android device? (Opposite of ACTION_AUDIO_BECOMING_NOISY)
One of the activity in my app connects to bluetooth scanner and get the input and display it in a listview. I got that working by following the bluetooth chat sample app. now the issue is, whenever screen is locked, or device goes to powersave mode, my connection with bluetooth scanner is getting disconnected. how can continue to keep the connection stays on until app is really closed from the system? I am new to Android . I did some search it says to use wakeful lock but how can i do that? Some samples would be much appreciated! Thanks for your time.
Instead of using wakeful lock, I would recommend you to implement the connection inside a background service.
The service runs until its killed by the system or you stop it.
You can found information including a simple example here:
http://developer.android.com/guide/components/bound-services.html
i have a problem with Androids NSD.
I registered a service using NsdManager on device A. With an other device B in the same WiFi i started the app "bonjour browser" which was able to discover the service. Fine.
But when i closed the app which registered my service on device A, the service is still available on the other device B using "bonjour browser". I killed the app and still the service is available. When i disable the wifi connection of device A the service disappears on device B. But when i reconnect to the wifi WITHOUT starting the service registration app, the services pops up again. Strange.
Is this normal? Do i need to explicit un-register the service? I thought that the service should disappear as soon as my app (and the NsdManager) is not working anymore.
Thanks for help.
I had a similar problem when using NSD on Android.
Your app should explicitly un-register the service before exiting.
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'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.