- 浏览: 1065028 次
- 性别:
- 来自: 南昌
文章分类
- 全部博客 (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 480平常我们遇到不清楚代码逻辑的,可以通过打印调用堆栈来理清楚,如 ... -
你知道Log.isLoggable
2018-11-23 14:15 958我们可以通过Log.isLoggable来动态开关log的输出 ... -
android:allowUndo
2018-04-25 16:51 781Android 在Android 23增加了UndoManag ... -
mipmap-xxx
2015-12-10 11:35 1103最近在看AOSP,发现mipmaps, 百度 了一下,发现有各 ... -
《Android.Programming.Pushing.the.Limits].Erik.Hellman》记录1
2015-10-29 10:56 579最近在看《Android.Programming.Pushin ... -
System.currentTimeMillis() uptimeMillis elapsedRealtime 区别
2015-10-28 20:02 1314转自http://blog.csdn.net/wutianyi ... -
GPS的开关设置
2015-09-29 18:36 2035//modify by hyxu 2015-9-30 to s ... -
DialogFragment
2015-09-25 13:56 1050public class YesNoDialog extend ... -
ANDROID L——RecyclerView,CardView导入和使用
2015-07-23 09:51 957转自http://blog.csdn.net/a3969019 ... -
Android media媒体库分析之:分类别统计媒体文件大小
2015-07-21 20:07 550转自http://www.linuxidc.com/Linux ... -
java.lang.IllegalArgumentException: Service Intent must be explicit
2015-07-21 20:03 1305转自:http://www.2cto.com/kf/20150 ... -
Context 和Application Context
2015-02-11 15:14 880http://possiblemobile.com/2013/ ... -
ContentProviderOperation.Builder 中withValue和withValueBackReference的区别
2015-02-10 14:01 2200关于ContentProviderOperation.Buil ... -
AndroidManifest.xml的Service元素 android:process设置
2013-05-30 17:02 11486转自:http://galin.blog.sohu ... -
android中打包含有Activity以及资源文件的jar包在工程中调用
2013-05-28 15:00 1320转自:http://www.cnblogs.com/vaiya ... -
Android杂谈--内存泄露(1)--contentView缓存使用与ListView优化
2012-11-01 09:29 2831转自:http://www.cnblogs.com/louli ... -
Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式
2012-10-31 14:32 1890转自:http://www.eoeandroid.com/th ... -
Animation
2012-10-30 13:41 1135转自:http://hi.baidu.com/wendaoer ... -
Android onTouchEvent和onInterceptTouchEvent
2012-10-24 15:05 1285ViewGroup里的onInterceptTouchEven ... -
Android 内存管理的相关知识
2012-10-15 14:03 1171最近在读柯元旦的《Android 内核剖析》一书的“内存管理” ...
相关推荐
android-services-demo, 用于服务和通知的Android演示( 星期 4 ) 服务演示这是一个用于服务和通知的Android演示,包括:使用 IntentService使用ResultReceiver在IntentService和 Activity 之间进行通信使用 ...
在Android应用开发中,`Service`和`IntentService`是两个关键组件,它们用于在后台执行长时间运行的任务,不依赖于用户界面。本篇将详细阐述`Service`和`IntentService`的用法以及需要注意的要点。 首先,我们来...
IntentService是Android系统中一种特殊的Service,它是Service的子类,设计用于在后台执行单一的任务,然后自动停止服务,不需要手动调用stopSelf()。...正确理解和使用IntentService能够提高应用的性能和用户体验。
在【标题】"IntentService实现,使用代码"和【描述】"一个IntentService的简单使用"中,我们可以深入探讨IntentService的基本概念、优点、工作原理以及如何在实际项目中使用。 1. **IntentService基本概念** ...
IntentService主要用于执行单一的任务或者一系列串行任务,而不会长时间占用主线程,提高了应用的响应速度和用户体验。 IntentService的核心特点是自动创建工作线程、处理Intent以及在任务完成后自动停止服务,这...
service中1需要手动开启子线程2服务开启之后会一直运行,需要手动调用stopService();或者stopSelf(); intentService是一种异步(子线程)、自动停止的服务,这个例子测试IntentService的特征
- **源码**:理解Service和IntentService的工作原理,需要阅读和分析Android系统的源代码,以便深入学习其内部机制。 - **工具**:开发过程中,可以利用Android Studio等IDE工具,以及调试工具进行服务的开发和测试...
IntentService的主要特点在于它自动管理了一个工作线程,接收到启动请求后,在这个工作线程中执行任务,完成后自动停止服务,避免了手动管理和停止服务的繁琐步骤。这样既保证了UI线程不被阻塞,又遵循了Android应用...
IntentService的使用既简单又高效,能够确保工作在安全的环境中,避免内存泄漏和线程安全问题。 在Android应用开发中,IntentService的主要特点和优势包括: 1. 单线程执行:IntentService内部使用了一个工作队列...
下面我们将详细分析IntentService的生命周期和工作流程。 1. 生命周期: - `onCreate()`: 当IntentService首次被创建时,这个方法会被调用。在这里,开发者可以进行一些初始化操作,如设置Handler或者初始化必要的...
以下是对Android线程、线程池、AsyncTask、HandlerThread和IntentService的详细解释。 1. **Android线程**: Android应用主要运行在主线程(UI线程)上,负责显示和交互。为了防止主线程被长时间运行的任务阻塞,...
在Android开发中,IntentService和Retrofit2.0是两个重要的组件,它们分别用于异步处理任务和网络请求。在本示例中,IntentService被用来实现后台下载文件,而Retrofit2.0则作为HTTP客户端,负责与服务器进行交互,...
IntentService具有自动管理线程和停止服务的特性,使得开发者能够轻松地实现耗时操作,如网络请求、数据同步等。下面我们将深入探讨IntentService的工作原理和如何使用。 IntentService的主要特点: 1. 单线程执行...
在处理大量后台任务时,使用IntentService可以显著提高应用程序的稳定性和用户体验。在实际开发中,特别是在处理网络请求、文件下载、数据库操作等可能阻塞主线程的任务时,IntentService是一个理想的选择。
通过"IntentService1"这个示例,你应该能掌握IntentService的基本使用和设计思想。实践过程中,理解IntentService如何处理并发和线程,以及如何与主线程通信,对于编写高效、健壮的Android应用至关重要。记得在实际...
与普通的Service相比,IntentService具有更好的线程管理和任务调度机制,使得开发者能更方便地处理异步操作。 1. **IntentService的基本特性** - **自动创建工作线程**:IntentService会自动创建一个工作线程来...
IntentService是Android系统提供的一种特殊类型的...理解和熟练使用IntentService,能够提高应用程序的性能和用户体验。在"Test"这个示例项目中,你可以通过查看代码和运行结果来进一步理解IntentService的运作机制。