1。无论是 Activity、BroadcastReceiver还是Service,只要是有长时间处理的任务,就需要重新开一个线程来处理,为什么会这样?

因为他们都是运行在主线程中的。

2。在使用BroadcastReceiver时,有一个我们需要注意的问题:

在BroadcastReceiver的onReceive(Context context , Intent intent )这个context是Activity还是Application?

如果你的BroadcastReceiver是通过在Activity中的registerReceiver(Broadcaster, filter)来注册的话,那么这个context就是这个Activity,

而如果是通过AndroidManifest来注册的话,那么这个context就是:android.app.ReceiverRestrictedContext。

3.AlarmManager对象配合PendingIntent使用,可以定时打开一个Activity,发送一个BroadCast或者开启一个Service。

4.AlarmManager 启动 BroadcastReceiver  ,BroadcastReceiver 再启动 Server

  The Alarm Manager holds a CPU wake lock as long as the alarm receiver's onReceive() method is executing. This guarantees that

the phone will not sleep until you have finished handling the broadcast. Once onReceive() returns, the Alarm Manager releases this

wake lock.

  This means that the phone will in some cases sleep as soon as your onReceive() method completes. If your alarm receiver

called Context.startService(), it is possible that the phone will sleep before the requested service is launched.

  To prevent this, your  BroadcastReceiver and Service will need to implement a separate wake lock policy to ensure that the phone

continues running until the service becomes available.

5.使用BroadcastReceiver实现开机启动Service或Activity

注册一个BroadcastReceiver用来监听手机开机Intent, 而该BroadcastReceiver又负责启动你的service或者activity.

6.连接本地web服务器

10.0.2.2

最新文章

  1. c/c++头文件_string
  2. ES6新增const常量、let变量
  3. Qt之自定义界面(右下角冒泡)
  4. Node.js stream 流学习
  5. WEB前端:浏览器(IE+Chrome+Firefox)常见兼容问题处理--01
  6. C# 判断网站是否能访问或者断链
  7. Java线程sleep,yield,join,wait方法详解
  8. 数据库概论_3标准化的SQL语言_ 数据定义
  9. 烧写uboot和openwrt固件ARxx系列
  10. 如何成为F1车手?
  11. GitHub Desktop下载及使用
  12. 13.缓存、三级缓存、内存溢出、AsyncTask
  13. Java大数统计-hdu1316
  14. AndroidStudio连不上Android设备真机
  15. Mouse Detected Problem
  16. Java并发编程的艺术(一)——并发编程需要注意的问题
  17. springboot中@EnableAsync与@Async注解使用
  18. js document.activeElement及使用
  19. PAT乙级1010
  20. 当inline-block或者float失效的时候怎么弄

热门文章

  1. supervisor配置详解
  2. python的post请求抓取数据
  3. create the web service by yourshelf
  4. 001servlet的基本知识
  5. 【BZOJ】1009: [HNOI2008]GT考试(dp+矩阵乘法+kmp+神题)
  6. identity_insert---实验性插入大批量数据和分页存储过程
  7. RabbitMQ之Queues-5
  8. 漫游Kafka设计篇之性能优化(7)
  9. 通过代码注册COM、DLL组件
  10. [转]VC++下使用ADO操作数据库