intentservice

Callback to jobservice from intentservcie

淺唱寂寞╮ 提交于 2019-12-07 05:20:42
问题 I have a jobscheduler that triggers onStartjob of Jobservice. In onStartJob, I start an intentservice to do the work. After the work is done, I want intentservice to do a callback to jobservice so that onjobfinished can be called. How can I do a callback to JobService? 回答1: You can create BroadcastReceiver and register it in your Jobservice , in onStartJob() method, using some ACTION constant (for example ACTION_DOWNLOAD_FINISHED ). This receiver will delegate all work to onJobFinished()

loop in IntentService

梦想与她 提交于 2019-12-07 01:09:19
问题 I have an infinite loop in my IntentService to update my view once every 30 seconds based on the input from the main activity. public class IntentServiceTest extends IntentService { String Tag = "IntentServiceTest"; String ACTION_RCV_MESSAGE = "com.jsouptest8.intent.action.MESSAGE"; public IntentServiceTest(){ super("IntentServiceTest"); Log.d(Tag, "IntentServiceTest constructor"); } @Override protected void onHandleIntent(Intent intent) { // TODO Auto-generated method stub Log.d(Tag, "in

how to wait the volley response to finish it's work inside intentservice?

淺唱寂寞╮ 提交于 2019-12-06 15:33:51
问题 Working with intentservice to get the data of 7 Rss Feed links with using " Google Volley " in the background and use ResultReceiver to get the result , But I can't configure how to wait on the volley response to finish it's job to fire flag with ResultReceiver to display the data in the MainActivity 回答1: You shouldn't wait for it. You have two ways to make a network request: synchronous and asynchronous. If you use synchronous, you don't wait for result because the network call is a blocking

Updating Activity UI from Intent Service?

社会主义新天地 提交于 2019-12-06 14:08:24
问题 I need to download some files (10-20 or depends on user) from service in my app. The problem is I am using IntentSevice and finding it hard to update activity UI. I know following ways to update UI Use handler and send messages from service to activity using Messenger like this. Send broadcast intents. Using first method would cause problem once activity is closed & re-opened and also I am not sure about its performance. Using second would definitely cause perfomance issues since I need to

Android复习强化笔记(二)

跟風遠走 提交于 2019-12-06 09:51:09
一:String、StringBuffer和StringBuilder之间的区别 String类型与StringBuffer类型主要性能区别其实在于String是不可变的对象,因此在每次改变String对象的时候其实都等于生成一个新的String对象,然后将新指针指向新的String对象。 StringBuffer是一个可变对象,但对它进行修改的时候不会像String那样重新建立对象。(线程安全) StringBuilder是一个可变对象,它跟StringBuffer相比不是线程安全的,一般在单个线程操作的时候,速度比StringBuffer快得多。(线程非安全) StringBuffer支持并发操作,线程安全,适合在多线程中使用;StringBuilder不支持并发操作,线程不安全,不适合在多线程中使用。 二:WebView http://www.open-open.com/lib/view/open1431569835951.html 基本使用: 1:在XML布局中添加WebView控件 2:在Manifest文件中添加权限:<uses-permission android:name="android.permission.INTERNET"/> 3:在java代码中获得该WebView的一个引用,同时使用loadUrl()加载一个网址 如:webView.loadUrl(

How to wait for an IntentService to finish its task

喜夏-厌秋 提交于 2019-12-06 08:49:59
I'm using an intent service to communicate with a server to get data for an app. I'd like the app to wait until the data it requests has been sent back (hopefully meaning that the IntentService the data has been requested from has finished running) before the app attempts to access or use the variables the data is to be stored in. How would I go about doing this? thanks! Easiest way is to have your IntentService send a Broadcast once it is done gathering data from the server, which you can listen to in your UI thread (e.g. Activity ). public final class Constants { ... // Defines a custom

Service and IntentService, Which is better to run a service that poll database value from the server?

一笑奈何 提交于 2019-12-06 08:31:18
I had read quite a number of resources regarding the Service and IntentService . However when come to make a decision, I am not confident enough to choose which type to use in order to create a background service that will poll data from database in a time interval and stop it when I get the data I want since the data represent a status of a request, eg. ordering medicine confirmation status(pending, completed, in progress). I need to detect when a status is set to "completed" and send a notification to alert the user that the order is completed. After that the service will stop itself

Android Thread vs AsyncTask vs IntentService called from BLE onCharacteristicChanged()

若如初见. 提交于 2019-12-06 08:08:24
I have an Android app from which I receive BLE data (every 62ms via notifications). The app can save data via a BufferedWriter to a file. Upon each onCharacteristicChanged() callback, I call either an AsyncTask, Thread or an IntentService to do a file write if the user enabled file save. The AsyncTask seems to work fine. But the docs say execute must be invoked on the UI thread, and I'm calling it from the BLE callback. Is that a problem? And how should I fix it? Using Thread causes this error: GKI_exception out of buffers https://code.google.com/p/android/issues/detail?id=65455 (except my

Android LocationLister implemented in IntentService never execute the OnLocationChanged() method

纵然是瞬间 提交于 2019-12-06 06:58:29
问题 I've written an IntentService which implements the LocationListener interface. The service should send a message when OnLocationChanged() method was called at the first time. But OnLocationChanged() is never called. Here's my code: public class MyIntentService extends IntentService implements LocationListener { private int result = Activity.RESULT_CANCELED; protected Messenger mMessenger; protected LocationManager mLocationManager = null; public MyIntentService() { super("LocationService"); }

Android: Toast from IntentService remains on screen for ever

ぐ巨炮叔叔 提交于 2019-12-06 03:16:38
I checked this question , but it doesn't appear to answer my problem, which is much less involved. I am calling an IntentService from a menu item in my main process. It is currently just a skeleton which puts up a Toast in onHandleIntent() which eventually should appear briefly at the end of the processing to say it's finished. However it remains on the screen for ever (even when the application is stopped). I tested both with the emulator and my Galaxy S2 with identical results. Can someone point me in the right direction, please? This is the service code: package com.enborne.spine; import