android-service

Context.startForegroundService did not then call Service.startForeground: Alternative solution

烂漫一生 提交于 2019-12-11 03:24:10
问题 Note: This question assumes you know binding a service to a context. Everyone on the production is aware of this issue, or even some users that have an Android Oreo or Pie device. The exception looks like this: Fatal Exception: android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground() at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1792) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop

Can WebView be used inside a service?

不问归期 提交于 2019-12-11 03:22:56
问题 I have an app that checks a specific website every one minute to see if it finds whatever I am looking for, then notifies me (Plays Sound) whenever the item is found. I followed this tut to make my app run in the background, but I noticed it complains about the WebView. http://marakana.com/forums/android/examples/60.html If it's not possible to use a WebView inside a service, what are my alternatives to achieve the same goal? Thank you! 回答1: No, a WebView should not be used inside a service,

Android music player app: how to set a complete listener for media player that is running in a service?

五迷三道 提交于 2019-12-11 03:03:19
问题 I'm writing an music player app. I have the MediaPlayer object in a service. The problem is that I don't know how to update the UI from service. By example I want to update the remaining time from current song but - because the MediaPlayer is on service - I can't set a listener to MediaPlayer object. I was thinking about sending a broadcast message with current time but if I'll do it in this way, I have to send a message on every second. I suppose this will affect the speed of application +

Catch NFC NDEF_DISCOVERED intent from a service

柔情痞子 提交于 2019-12-11 02:52:23
问题 I have a service which is always running in the background, is there a way that I can catch an NDEF_DISCOVERED intent filter in my service? So that once my two devices are ready to beam I can catch that code in a service and manipulate it as I need too? 回答1: The NFC intents, that is android.nfc.action.NDEF_DISCOVERED, android.nfc.action.TECH_DISCOVERED, and android.nfc.action.TAG_DISCOVERED, are only sent to activities. Thus, you cannot catch them from a service directly. However, you could

Android process importance with a started service isn't IMPORTANCE_SERVICE

匆匆过客 提交于 2019-12-11 02:07:31
问题 I'm trying to better understand process priorities in android especially when there is a service running in the same process where activities lives. Android documentation explains that when there is a service started and the application goes in background the process will be a "Service process" with a higher rank in respect of a normal background process. http://developer.android.com/guide/components/processes-and-threads.html Process Lifecycle 3. Service process A process that is running a

Send data from service to activity and screen rotation

删除回忆录丶 提交于 2019-12-11 02:06:03
问题 I am using an Intent Service that performs an action and needs to pass back to the activity that started it the results of the action. I've searched through dozens of similar posts but as far as i can tell, all solutions i found have a problem. They don't handle well screen rotation. Suppose an activity starts the Intent Service, the service takes 10 seconds to perform the action, and during those 10 secs, the screen gets rotated. The activity gets destroyed and a new one is created. Use

Running OpenCV eye detection from within Android service

霸气de小男生 提交于 2019-12-11 01:58:21
问题 I want to run eye detection by OpenCV4Android from Android background service. I have a piece of code that runs well but as an Activity not service. I understand that the Android camera must have a preview to open. So I have created a preview (small one to make it looks hidden, since I want the processing to be in the background) and started the camera for recording. The camera starts successfully, but OpenCV doesn't detect eyes and faces. It only loads the xml classifiers. I expected the

Remove ongoing notification from service

守給你的承諾、 提交于 2019-12-11 01:53:31
问题 I have a service that create a notification when it is started. And then ondestroy() i want it to be removed. I just use .cancel(NOTIFICATION_ID); It works great when it is a normal notification but when i am using ongoing event it just won't cancel it. I did read something about that services doesn't stop if android have the resources for it, but how to overcome this? I use this code to start the service final Intent bg_service = new Intent(BackgroundService.class.getName()); btn_start =

Android - Best practice for a periodic service

…衆ロ難τιáo~ 提交于 2019-12-10 23:55:59
问题 I want to implement a service which its job is to periodically fetch updates from Internet. I know there is couple of ways to accomplish this purpose. I will list 2 of them. Please tell me what is more efficient and in practice what way is more common. Thanks in advance 1.Implement an infinite while(true) loop inside a separate thread, and then run this thread in service's onStartCommand . pseudo code: class Updater extends Service { ... public int onStartCommand(Intent intent, int flags, int

Sticky Service restarts after Application close

廉价感情. 提交于 2019-12-10 23:40:02
问题 i have troubles with my STICKY Service. I call it in my MainActivity.class and bind it: MainActivity : Intent intent = new Intent(this, MyService.class); ComponentName MyCompName= startService(intent); bindService(intent, MyConnection, Context.BIND_AUTO_CREATE); and... MyService @Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); return START_STICKY; } I want that this Service runs STICKY and never be closed or restarted.