首页 > 移动平台 > 详细

android 知识收集

时间:2014-07-22 23:17:24      阅读:704      评论:0      收藏:0      [点我收藏+]

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

android 知识收集

原文:http://www.cnblogs.com/yuyutianxia/p/3514067.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!