- 浏览: 1075919 次
- 性别:
- 来自: 南昌
-
文章分类
- 全部博客 (276)
- 生活 (1)
- 代码之美 (22)
- Media (7)
- Android Widget (3)
- Android Intent (1)
- Android Activity (4)
- UI event handle--UI事件处理机制 (2)
- Java基础知识 (12)
- android Databases (5)
- Android 系统知识 (70)
- 平常遇到的问题与解决方法 (38)
- Android TextView/EditView (2)
- Thinking Java (1)
- android webkit (6)
- JSON (1)
- XML (4)
- HTTP (1)
- Google Weather API (1)
- android 2.3 NFC (10)
- android app (20)
- android framework (7)
- C++ (2)
- android System (5)
- Pthread (1)
- Wifi (8)
- Unix/Linux C (8)
- Android 4.0 (1)
- Mail (1)
- Smack 源码学习 (4)
- iOS (4)
- Android (1)
- git (1)
- Gallery3d (2)
- React-Natice (1)
最新评论
-
dd18349182956:
你是用的smack哪个版本?我用的smack4.1.3和sma ...
关于socket长连接的心跳包 -
xukaiyin:
全英文
getApplicationContext()与this,getBaseContext() -
裂风矢:
...
<category android:name="android.intent.category.DEFAULT" /> 惹的祸 -
xanthodont:
mark一下
XMPP——Smack -
Evilover3:
mark一下,学习了
XMPP——Smack
转自[url] http://javatechig.com/android/creating-a-background-service-in-android[/url]
1. What is IntentService?
IntentService is a subclass of android.app.Service class. A stated intent service allows to handle long running tasks without effecting the application UI thread. This is not bound to any activity so, it is not getting effected for any change in activity lifecycle. Once IntentService is started, it handles each Intent using a worker thread and stops itself when it runs out of work.
IntentService would be an best solution, If you have an work queue to process. For example, if your application using analytics you will likely to send event name and related parameter to your tracking server for each user generated event. Although each event means a tiny piece of data, creating networking request on each click will result an overhead to your application. Instead, you can use work queue processor design pattern and process the events in a batch.
2. IntentService Limitations
No easy or direct way to interact with user interface directly from IntentService. Later in this example, we will explain to pass result back from IntentService to
With IntentService, there can only be one request processed at any single point of time. If you request for another task, then the new job will wait until the previous one is completed. This means that IntentService process the request
An tasks stated using IntentService cannot be interrupted
3. Why do we need IntentService?
Android design guidelines strongly suggests to perform all the long running tasks off the UI thread. For example, if you have to periodically download the largest chunk of data from server, you must use IntentService to avoid ANR. ANR (Application not responding) message often occurs, if your main thread is doing too much of work. In this course of this tutorial, we will learn the below concepts
How to create and use IntentService
How to pass data from activity to service as parameter
How to pass result back to activity
Update activity based on the result
Case Study
To make this tutorial easy to understand we will extend our previous tutorial (Android Networking Tutorial) to use Intent Service for downloading the data from server. We suggest you to checkout Android Networking Example to get familiar with downloading data from server using different http clients available in Android.
Feed Url : http://javatechig.com/api/get_category_posts/?dev=1&slug=android
Expected Result Start service to download the data when application is started. Once download is complete, update ListView present in your activity.
1. What is IntentService?
IntentService is a subclass of android.app.Service class. A stated intent service allows to handle long running tasks without effecting the application UI thread. This is not bound to any activity so, it is not getting effected for any change in activity lifecycle. Once IntentService is started, it handles each Intent using a worker thread and stops itself when it runs out of work.
IntentService would be an best solution, If you have an work queue to process. For example, if your application using analytics you will likely to send event name and related parameter to your tracking server for each user generated event. Although each event means a tiny piece of data, creating networking request on each click will result an overhead to your application. Instead, you can use work queue processor design pattern and process the events in a batch.
2. IntentService Limitations
No easy or direct way to interact with user interface directly from IntentService. Later in this example, we will explain to pass result back from IntentService to
With IntentService, there can only be one request processed at any single point of time. If you request for another task, then the new job will wait until the previous one is completed. This means that IntentService process the request
An tasks stated using IntentService cannot be interrupted
3. Why do we need IntentService?
Android design guidelines strongly suggests to perform all the long running tasks off the UI thread. For example, if you have to periodically download the largest chunk of data from server, you must use IntentService to avoid ANR. ANR (Application not responding) message often occurs, if your main thread is doing too much of work. In this course of this tutorial, we will learn the below concepts
How to create and use IntentService
How to pass data from activity to service as parameter
How to pass result back to activity
Update activity based on the result
Case Study
To make this tutorial easy to understand we will extend our previous tutorial (Android Networking Tutorial) to use Intent Service for downloading the data from server. We suggest you to checkout Android Networking Example to get familiar with downloading data from server using different http clients available in Android.
Feed Url : http://javatechig.com/api/get_category_posts/?dev=1&slug=android
Expected Result Start service to download the data when application is started. Once download is complete, update ListView present in your activity.
- Android-IntentService-Example-master.zip (113.1 KB)
- 下载次数: 0
发表评论
-
打印调用堆栈
2019-11-15 15:48 544平常我们遇到不清楚代码逻辑的,可以通过打印调用堆栈来理清楚,如 ... -
你知道Log.isLoggable
2018-11-23 14:15 1026我们可以通过Log.isLoggable来动态开关log的输出 ... -
android:allowUndo
2018-04-25 16:51 843Android 在Android 23增加了UndoManag ... -
mipmap-xxx
2015-12-10 11:35 1152最近在看AOSP,发现mipmaps, 百度 了一下,发现有各 ... -
《Android.Programming.Pushing.the.Limits].Erik.Hellman》记录1
2015-10-29 10:56 616最近在看《Android.Programming.Pushin ... -
System.currentTimeMillis() uptimeMillis elapsedRealtime 区别
2015-10-28 20:02 1370转自http://blog.csdn.net/wutianyi ... -
GPS的开关设置
2015-09-29 18:36 2098//modify by hyxu 2015-9-30 to s ... -
DialogFragment
2015-09-25 13:56 1091public class YesNoDialog extend ... -
ANDROID L——RecyclerView,CardView导入和使用
2015-07-23 09:51 988转自http://blog.csdn.net/a3969019 ... -
Android media媒体库分析之:分类别统计媒体文件大小
2015-07-21 20:07 583转自http://www.linuxidc.com/Linux ... -
java.lang.IllegalArgumentException: Service Intent must be explicit
2015-07-21 20:03 1351转自:http://www.2cto.com/kf/20150 ... -
Context 和Application Context
2015-02-11 15:14 915http://possiblemobile.com/2013/ ... -
ContentProviderOperation.Builder 中withValue和withValueBackReference的区别
2015-02-10 14:01 2246关于ContentProviderOperation.Buil ... -
AndroidManifest.xml的Service元素 android:process设置
2013-05-30 17:02 11537转自:http://galin.blog.sohu ... -
android中打包含有Activity以及资源文件的jar包在工程中调用
2013-05-28 15:00 1357转自:http://www.cnblogs.com/vaiya ... -
Android杂谈--内存泄露(1)--contentView缓存使用与ListView优化
2012-11-01 09:29 2874转自:http://www.cnblogs.com/louli ... -
Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式
2012-10-31 14:32 1921转自:http://www.eoeandroid.com/th ... -
Animation
2012-10-30 13:41 1167转自:http://hi.baidu.com/wendaoer ... -
Android onTouchEvent和onInterceptTouchEvent
2012-10-24 15:05 1323ViewGroup里的onInterceptTouchEven ... -
Android 内存管理的相关知识
2012-10-15 14:03 1206最近在读柯元旦的《Android 内核剖析》一书的“内存管理” ...
相关推荐
android-services-demo, 用于服务和通知的Android演示( 星期 4 ) 服务演示这是一个用于服务和通知的Android演示,包括:使用 IntentService使用ResultReceiver在IntentService和 Activity 之间进行通信使用 ...
不过,由于IntentService运行在单独的工作线程,不能直接更新UI,所以通常配合BroadcastReceiver或者使用ResultReceiver进行通信。 4. LiveData和ViewModel:这是Android架构组件的一部分,LiveData是一个观察者...
- **android.os**:`AsyncTask`类的加入简化了异步任务的执行,`ResultReceiver`则优化了任务结果的传递。 - **android.preference**:偏好设置管理功能得到加强,便于创建自定义设置界面。 - **android.provider**...
4. 发送有序广播:发送有序广播使用Context的sendOrderedBroadcast()方法,传入Intent和一个ResultReceiver(可选),用于接收广播接收者的返回结果。 例如: ```java Intent intent = new Intent(...