android-service

When can onTaskRemoved() be called?

让人想犯罪 __ 提交于 2019-11-29 06:06:32
The docs state that This is called if the service is currently running and the user has removed a task that comes from the service's application. It seems as if it is only called when the app is swiped away from the recent task list. Pressing the back button until all Activities are destroyed in the task does not cause this to be called. Are there other scenarios where this could be called? Pressing the back button until all Activities are destroyed in the task does not cause this to be called. Finishing Activities by pressing the back button doesn't mean that running services and the

Turn on Unknown Sources setting programmatically

两盒软妹~` 提交于 2019-11-29 05:01:41
I want to turn on Unknown Sources setting programmatically on non rooted device. I have checked with this code: boolean success; int result = Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, 0); if (result == 0) { success = Settings.Secure.putString(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, "1"); } and with following permissions: <uses-permission android:name="android.permission.WRITE_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/> but on executing, it says permission denied: writing to secure

Can I call stopSelf() in Service.onStartCommand?

♀尐吖头ヾ 提交于 2019-11-29 04:21:42
问题 There are some conditions where my service could be attempted to be started when it should not be. In cases like this is it bad form to call stopSelf() while inside a onStartCommand() method? If so what is the best way to handle such a situation? Any resources will be greatly appreciated. 回答1: is it bad form to call stopSelf() while inside a onStartCommand() method? Off the top of my head, I can't think of why that would be a problem. stopSelf() , like a lot of stuff in Android, has no

Service being killed while holding wake lock and after calling startForeground

送分小仙女□ 提交于 2019-11-29 04:09:56
问题 I am having a problem where my service is being killed even though I am holding a wake lock and I have called startForeground . When this occurs the tablet (ASUS Transformer TF101), stops the service without calling onDestroy . There are no other apps visible, and log cat shows nothing out of the ordinary (no 'out of memory' message etc). Immediately after being killed, the service restarts. The app I am developing is a chat client and needs a constant connection, it is also plugin based, so

Creating a Service in Android

心已入冬 提交于 2019-11-29 04:04:25
I'm creating my first android app and I need to use a service. The UI will have a checkbox (CheckBoxPreference) that will be used to turn the service on/off and the service will only be accessed by my app (there's no need to share it). So far the UI for this functionality is ready and I know how to respond to the event, what I dunno is how to create a service nor how to connect to it whatsoever. The idea is that the service continues to listen for events and responding to them on the background and that the application is only to used to turn it on/off or to change some settings. I've looked

Service Automatic Called on Destroying Activity

女生的网名这么多〃 提交于 2019-11-29 03:41:51
I am stuck with the problem of Activity + Service in that I have following number of Activities and Services. Activities: LoginActivity => OrderListActivity => AddOrderActivity => ConfirmOrderActivity Services: ReceivingOrderService - Receiving New Data From Server SendingOrderService - Sending new Data to Server Above both Service Calling from another Separate Service on duration of some interval . CheckAutoSyncReceivingOrder - To call ReceivingOrderService (Interval 15Mins) CheckAutoSyncSendingOrder - To call SendingOrderService (Interval 3Mins) CheckAutoSyncReceivingOrder: public class

Communication between Android Services and Activities

寵の児 提交于 2019-11-29 02:37:45
I want to develop an Android App with three activities and two services. The first Service, named WebClientService , calls a REST API every 30 seconds, using an Handler, and has to notify the active Activity with the result. It also has to notify a second Service, named DatabaseService , in order to update a local DB. The Database Service will be called just once onCreate of the activity (in case of app crash and restart) and just once at onRestart (in this way we have data to show in case there were connectivity issues). The activities will then keep themselves updated thanks to the

BroadcastReceiver or Messenger via Handler

半腔热情 提交于 2019-11-29 02:30:22
问题 I have an IntentService which need to pass a message to an Activity . I know two ways of doing so. use sendBroadcast() at the Service side while registering a broadcastReciever at the Activity side which will receiver the message. passing a Messenger to the Service side , which will point to a Handler at the Activity side, which will be ready to receive that message from the service. Which one is good for which purpose? Or both of them do the same? 回答1: If your IntentService does not know

Obtain Android GPS location once every few minutes

烈酒焚心 提交于 2019-11-29 02:26:36
I would like to write an app on Android to upload my GPS location to an external website once every ~5 minutes. This needs to have as minimal an impact on battery life as possible, but it also needs to work without any user interaction. (Background: I'm competing in an Ironman triathlon which will take me about 14 hours to complete, and want to broadcast my location in near-real-time but without having to worry about fiddling with my phone.) So my initial thought is to write a Service which uses LocationManager.requestLocationUpdates() with a minTime of 5 minutes, but will this actually wake

part-1 persistent foreGround android service that starts by UI, works at sleep mode too, also starts at phone restart

六眼飞鱼酱① 提交于 2019-11-29 02:01:27
Status:--- I equally accept Karakuri's and Sharad Mhaske's answer , but since Sharad Mhaske answer after the start of bounty , the bounty should go to him. Part-2 made: part-2 persistent foreGround android service that starts by UI, works at sleep mode too, also starts at phone restart In stack overflow , only one answer may be accepted . I see both answers as acceptable but one has to be chosen (I chosed at random). Viewers are invited to up/down vote answers/question to appreciate the effort! . I upvoted Karakuri's answer to compensate reputation. Scenario:--- I want to make the user click a