IntentSvice和Service的区别

首先IntentService是继承自Service的,那我们先看看Service的官方介绍,这里列出两点比较重要的地方:

1.A Service is not a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.

2.A Service is not a thread. It is not a means itself to do work off of the main thread (to avoid Application Not Responding errors).

稍微翻一下(英文水平一般)

1.Service不是一个单独的进程 ,它和应用程序在同一个进程中。

2.Service不是一个线程,所以我们应该避免在Service里面进行耗时的操作

关于第二点我想说下,不知道很多网上的文章都把耗时的操作直接放在Service的onStart方法中,而且没有强调这样会出现Application Not Responding!希望我的文章能帮大家认清这个误区(Service不是一个线程,不能直接处理耗时的操作)。

有人肯定会问,那么为什么我不直接用Thread而要用Service呢?关于这个,大家可以网上搜搜,这里不过多解释。有一点需要强调,如果有耗时操作在Service里,就必须开启一个单独的线程来处理!!!这点一定要铭记在心。

IntentService相对于Service来说,有几个非常有用的优点,首先我们看看官方文档的说明:

IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests throughstartService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.

This "work queue processor" pattern is commonly used to offload tasks from an application's main thread. The IntentService class exists to simplify this pattern and take care of the mechanics. To use it, extend IntentService and implement onHandleIntent(Intent). IntentService will receive the Intents, launch a worker thread, and stop the service as appropriate.

All requests are handled on a single worker thread -- they may take as long as necessary (and will not block the

application's main loop), but only one request will be processed at a time

自己写了一个 测试 直接用Service 中写了一个耗时操作 居然进程没挂掉 ,,,用IntentService 写的进程居然挂掉了。。很纠结

dong.css 是一个 CSS 样式表文件,主要用于美化规范特定编辑器或页面内编写的文本内容。它为各种 HTML 元素(如段落、标题、列表、引用、链接、代码块等)定义了一系列样式,旨在提升文本的可读性视觉效果,打造出美观且专业的排版风格。 无论是撰写技术文档、博客文章、学习笔记,还是项目文档,都可以借助这个样式表来让文档更加美观易读。在开发 Web 应用、个人网站或博客时,若需要展示代码文本内容,该样式表可以帮助他们快速实现内容的美观排版。在使用支持 CSS 样式的 Markdown 编辑器(如 Typora)时,将该样式表应用到本地文档中,使文档在编辑过程中就呈现出良好的视觉效果。 功能说明 文本区域布局:设置文本编辑区域的最大宽度、左右内边距,调整行高、单词字母间距。 字体设置:使用现代无衬线字体,调整字体大小颜色。 段落:设置段落的字体大小、上下内边距行高。 标题:为各级标题设置不同的字体大小、颜色、间距样式,突出标题层次结构。例如,一级标题居中显示并带有下划线,二级标题部分文字有蓝色背景特殊效果等。 列表:为无序列表有序列表设置不同的样式内边距,嵌套列表也有独特的样式。 引用:为引用区域设置左边框、背景颜色圆角。 链接:设置链接的颜色、下划线鼠标悬停效果。 行内代码:为行内代码设置背景颜色、字体颜色、圆角等宽字体。 图片:为图片设置居中显示、上下外边距、圆角阴影效果。 表格:设置表格的宽度、边框合并、奇偶行背景颜色表头样式。 脚注:为脚注上标脚注定义名称设置特殊样式,如添加方括号 代码块:为代码块设置顶部背景区域、背景颜色、字体颜色、圆角不同类型代码元素的颜色,使代码块内容更加美观易读。同时,还设置了代码块中光标的宽度颜色。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值