惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
S
Security @ Cisco Blogs
G
GRAHAM CLULEY
L
LINUX DO - 热门话题
AWS News Blog
AWS News Blog
P
Privacy International News Feed
Cyberwarzone
Cyberwarzone
P
Proofpoint News Feed
腾讯CDC
美团技术团队
宝玉的分享
宝玉的分享
博客园 - 聂微东
小众软件
小众软件
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
雷峰网
雷峰网
T
Threatpost
The Hacker News
The Hacker News
P
Palo Alto Networks Blog
L
LangChain Blog
Cisco Talos Blog
Cisco Talos Blog
G
Google Developers Blog
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Engineering at Meta
Engineering at Meta
T
Troy Hunt's Blog
F
Full Disclosure
博客园_首页
The Last Watchdog
The Last Watchdog
S
Secure Thoughts
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
PCI Perspectives
PCI Perspectives
Microsoft Security Blog
Microsoft Security Blog
S
Security Affairs
量子位
Cloudbric
Cloudbric
H
Hacker News: Front Page
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
LINUX DO - 最新话题
IT之家
IT之家
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Spread Privacy
Spread Privacy
Forbes - Security
Forbes - Security
Security Archives - TechRepublic
Security Archives - TechRepublic

博客园 - 拿走不谢

20190131 经验总结:如何从rst文件编译出自己的sqlalchemy的文档 Python学习笔记:Flask-Migrate基于model做upgrade的基本原理 20180821 Python学习笔记:如何获取当前程序路径 网络编程之 keepalive(zz) java socket编程中backlog的含义(zz) 20170814 新鲜:EChart新增了日历图,要想办法用起来 Canvas 和 SVG 的不同 androidstudio全局搜索快捷键Ctrl+Shift+F失效的解决办法 Android support 26.0.0-alpha1 产生的问题(zz) 20170711 通过阿里云与国家气象局合作的api读取历史辐照数据 Android、iOS、和Web如何做灰度发布? 周鸿祎《智能主义》读书笔记 《Python数据分析与挖掘实战》读书笔记 《腾讯传》读书笔记 《如何高效学习》读书笔记 版本控制:tortoise svn的 revert to this revision和 revert changes from this revision有什么区别? Android: Android Studio签名打包的两种方式(zz) Android:如何生成自己的keystore(zz) android:Android中用文件初始化sqlite数据库(zz)
android:第十章,后台的默默劳动者——服务,学习笔记
拿走不谢 · 2017-05-20 · via 博客园 - 拿走不谢

一、多线程

1)本章首先介绍了安卓的多线程编程,说明在子线程中如果要修改UI,必须通过Handler, Message, MessageQueue, Looper来实现,但是这样毕竟太麻烦了。

 

2)然后紧接着就给出了AsyncTask,通过继承这个类,就可以在他的里面直接修改UI元素,方便很多;

二、服务

1)首先给出服务的常规方法,比如创建onCreate、启动onStartCommand、停止onStop、销毁onDestroy;

2)然后说明了Activity和Service之间如何通信,这里要借助一个Binder和ServiceConnection两个抽象类,当然还有Activity中的bindService, unbindService方法,

3)接线来就提出了前台服务的概念了,这个确实现在很多程序都在用,其实实现起来很简单,就是借助于我们在第八章中的系统通知的Notification,然后再调用setForeground(xxxx)来实现;

4)紧接着IntentService出现了;

    其实开篇作者就提出了一个问题,不要被后台服务这个名字所迷惑,其实服务默认都是运行在主线程的,所以如果在里面做很耗时的事情的主线程就会很卡,会出现ANR,所以我们还是要考虑使用真正的后台服务,也就是IntentService。

最后作者给出了一个完整的例子,在例子中,作者没有使用IntentService,而是使用Service+AsyncTask的方式,后面我倒是可以考虑使用IntentService来重写一下这个例子。