android-service

IntentService + startForeground vs JobIntentService

偶尔善良 提交于 2019-11-27 22:37:41
问题 Since Android Oreo background execution limits, the docs recommend to refactor IntentService s to JobIntentService . https://developer.android.com/about/versions/oreo/background JobIntentService runs immediately as an IntentService below Oreo, but schedules a Job on Oreo+ https://developer.android.com/reference/android/support/v4/app/JobIntentService In what cases would it make sense to run a normal IntentService as a foreground Service with a persistent notification, and when is a

Communication between Android Services and Activities

和自甴很熟 提交于 2019-11-27 21:54:44
问题 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

Send Data from Service To Activity Android

一个人想着一个人 提交于 2019-11-27 21:29:57
I am building a music player that uses a service for playback. I have an Activity UI that controls (play, pause, next, ...) the service. I want to update the UI from my service when the next or previous button is pressed. I thought of passing an integer value. Here is my code: I have used a messenger for communication. The code in my service looks like: enum Event { NextSongChanged, CurrentPlayingSong }; public synchronized void registerHandler(Messenger m) { clients.add(m); } private void emit(Event e) { for (Messenger m : clients) { try { m.send(Message.obtain(null, e.ordinal())); } catch

Concurrent writing to android database (from multiple services)?

廉价感情. 提交于 2019-11-27 21:29:24
I've a serious problem with android sqlite database and concurrent writing. For better explanations, I will give you a real life example: I've an desktop widget, where I'm showing a list of items from my database (and on background I have DataService, which in regular intervals collects fresh data from my remote server, and update my database with them). So - when i click on some item in list, i need to update clicked item (=do write operation) in database. BUT when i click on item exactly in moment, when DataService is updating fresh data in my database, it of course logs an error like this:

Always show service in notification bar

女生的网名这么多〃 提交于 2019-11-27 21:03:41
问题 I want to add my app to the notification bar so that it always shows, like some apps in the Google Play store. I want it to be like this screen shot: I want my notification to not be cleared, and for my app to be opened when the notification is clicked. Here's My Service Class Code: package com.demo; import java.util.Random; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Intent;

Android Library Manifest vs. App Manifest

戏子无情 提交于 2019-11-27 20:23:36
I've read similar questions here, but am still not clear on a couple of things. Using a Library Project means that my overall project will have two manifests -- one for the library and the other for the "main" app project -- and I'm not clear what goes in which or if there is some redundancy. I'm developing an app widget with "lite" and "paid" versions, so will have almost all code in a library project. Being a widget, the library will have at least a receiver, a service, a configuration activity, plus a couple of other activities. So where should the full declarations of these components --

Android Emulator: How can I get a list of services that are running

只谈情不闲聊 提交于 2019-11-27 20:22:52
问题 I have the Android Emulator running in my Ubuntu VM and just installed an apk file trough the console. The emulator and adb have many options to view what is going on on the device. But how can I get a list of services that are currently running? I'm trying to find out if a specific app installes a notify service to view (unwanted) ads. I even know the services' name. PS.: I'm an advanced beginner - but not advanced enough. So thanks for your help. 回答1: You can get the list with the following

Android - Firebase jobdispatcher

空扰寡人 提交于 2019-11-27 19:52:05
I would like to know if it's possible to use Firebase jobdispatcher to schedule an url hit and get the response in order to update the db. I would like it to run once per day at night. Does anyone know if this is possible? I can't find any good example of doing this. I already read android documentation and https://github.com/firebase/firebase-jobdispatcher-android#user-content-firebase-jobdispatcher- . I need to use Firebase jobdispatcher because I'm targeting API 16. Thanks in advance. UPDATE This is what I did to schedule it once per day. final int periodicity = (int) TimeUnit.HOURS

Wake locks android service recurring

馋奶兔 提交于 2019-11-27 19:12:00
I have this application that needs to run a service (background) that beeps periodically. The phone needs to beep the entire day for 5 seconds every one minute (used a handler in the service). I have implemented this service which does this perfectly, but when the phone goes into deep sleep mode, the execution stops of this handler stops. Using this answer from the question in SO, I managed to use wake locks and it works fine. But when I explicitly put the phone in deep sleep mode, the handler stops executing. Where do I place the wakelock in the service. Code snippet below. public class

Cannot keep android service alive after app is closed

廉价感情. 提交于 2019-11-27 19:10:54
I am trying to spawn a service that stays alive all the time, even if the user closes the application. According to these threads Keep location service alive when the app is closed Android Service Stops When App Is Closed Android: keep Service running when app is killed this can be accomplished with IntentServices or Service.START_STICKY Yet, I tried both types of services without success. In other words, my services get killed when the app is closed by the user. Can someone point out if this is can be done and how? Here is what I have tried without success: With IntentService: public class