Category: C #, Android, VS2015;Date Created: 2016-03-01 I. INTRODUCTIONTo further simplify the use of the intent filter, the Android system also provides a Intentservice class, so that you do not need to rewrite other methods, directly implement a class that inherits from Intentservice, Then rewrite the Onhandleintent
Android BASICS (II), Service and IntentService, androidintentI. Overview the lifecycle of the activity of the four major components in the previous article. This article will introduce another component service that is most similar to the activity and its subclass intentService, the service component is the most similar to the activity component among the four
In Android development, we may encounter such a business need, a task is divided into several sub-tasks, sub-tasks executed sequentially, after the completion of all subtasks, the task is only successful. Then, it is possible to do this with a few sub-threading sequence execution, but each thread must be manually controlled, and another child thread will be opened after one of the sub-threads has finished executing. Or, put them all in one thread and
OnDestroy () {Super.ondestroy (); }}After launching the application, print as follows:We found that: started two services, performed a oncreate, two times Onstartcommand and thread id=1, stating that the service was executed on the UI thread, performed two onhandleintent and thread id = 234, explaining the abstract method Onh The andleintent is executed in a sub-thread, so the time-consuming task can be executed in this method.And you will find that when the second task is finished, the printou
Android IntentService vs ServiceAndroid IntentService vs Service
As we all know, services in Android are used for background services. When an application is mounted to the background, services, such as playing music, are introduced to ensure that some functions in the application can still work. For the service, the o
the corresponding Looper,handler and add a Message object with the customer intent in the MessageQueue, When Looper finds a message, it then gets the Intent object by calling your handler in Onhandleintent ((Intent) msg.obj) and stops its service after processing. This means that the life cycle of intent is consistent with the task you are dealing with, so this class is very good with the download task, and the service itself ends the exit after the download task finishes. The characteristics o
polling messages are sequential, so when there are multiple background tasks, will be executed in the order of the outside.Example: class myintentservice extends intentservice{ PublicMyintentservice (String name) {Super(name); } @Overrideprotected voidOnhandleintent (Intent Intent) {String Name=intent.getstringextra ("Football"); LOG.I (Constants.log,name); } @Override Public voidOnDestroy () {Super. OnDestroy (); LOG.I (Constants.LOG,
What is intentservice?The official explanation is:
Intentservice is a base class for services that handle asynchronous requests (expressed as intents) on demand. clients send requests through android. content. context. startservice (intent) CILS; the service is started as needed, handles each intent in turn using a worker thread, and stops itself when it runs out
the corresponding Looper,handler and add a Message object with the customer intent in the MessageQueue, When Looper finds a message, it then gets the Intent object by calling your handler in Onhandleintent ((Intent) msg.obj) and stops its service after processing. This means that the life cycle of intent is consistent with the task you are dealing with, so this class is very good with the download task, and the service itself ends the exit after the download task finishes. The characteristics o
"); I.putextras (bundle); StartService (i); Intent i2 =NewIntent ("Cn.scu.finch"); Bundle Bundle2 =NewBundle (); Bundle2.putstring ("TaskName","Task2"); I2.putextras (Bundle2); StartService (I2); StartService (i);//Multiple start-up}}Operation Result: Intentservice opens a thread in the OnCreate () function to process all the tasks of the intent request object in turn by Handlerthread. Passed to the service via Ons
What is intentservice? (This article from http://blog.csdn.net/gaojie314/archive/2010/11/28/6040701.aspx)The official explanation is: intentservice is a base class for service
S that handle asynchronous requests (expressed as intent
S) on demand. clients send requests through Android. content. Context. startservice (intent)
CILS; the service is started as needed,
Android --- 43 --- IntentService of Service, androidintentZookeeper
First, let's talk about two problems of the Service itself:
1. The Service does not start a new thread. The Service and its application are in the same process.
2. The Service is not a new thread, so it should not process time-consuming tasks in the Service.
IntentService makes up for these two
Intentservice Service is also a service of wirelessly, it inherits with the service, but unlike Servcie, it opens a new thread to handle all requests, does not need the UI waits for processing, the Onstartcommand method sends all requests to the work queue, , and then sent by the work queue to onhandlerintent for processing1.interservice by default, a new thread is opened to handle the task, and service defaults to the UI thread execution2. Interservi
/cn.codingblock.androidadvancestudy I/myservice: I'm a time-consuming task, execution remaining time: 012-07 17:53:20.924 29898-30563/ Cn.codingblock.androidadvancestudy I/myintentservice: I'm a time-consuming task, execution remaining time: 012-07 17:53:21.830 29898-29898/ Cn.codingblock.androidadvancestudy i/servicetestactivity: I'm a time-consuming task, execution remaining time: 0From the log, the time-consuming tasks of starting a child thread in the normal service and the tasks in the
onbind (Intent Intent) {return null;} @Overridepublic int Onstartcommand (Intent Intent, int flags, int startid) {//The time-consuming task within this method may cause ANR (application not Responding) exception long endTime = System.currenttimemillis () + 20 * 1000; System.out.println ("OnStart"), while (System.currenttimemillis () Myintentservice.java:public class Myintentservice extends Intentservice{public Myintentservice () {Super ("Myintentserv
Android time-consuming task _ IntentServiceIf you see the BackService class mentioned in the previous android time-consuming task _ HandlerThread, you must have an impulse to encapsulate it for ease of use.Don't worry. The Android SDK has already provided us with the IntentService class that is basically the same as th
Many netizens may find that there is a intentservice in addition to the service in Android, what is the difference between them? In terms of inheritance, Intentservice is a subclass of service, and the internally implemented code involves some of the Android starter developers who don't understand the looper,android123
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.