摘要: public static final int ELAPSED_REALTIME //当系统进入睡眠状态时,这种类型的闹铃不会唤醒系统。直到系统下次被唤醒才传递它,该闹铃所用的时间是相对时间,是从系统启动后开始计时的,包括睡眠时间,可以通过调用SystemClock.elapsedRealtime()获得。系统值是3 (0x00000003)。 public static final int ELAPSED_REALTIME_WAKEUP //能唤醒系统,用法同ELAPSED_REALTIME,系统值是2 (0x00000002) 。 ... 阅读全文
posted @ 2012-10-29 18:40 water0504 阅读(253) 评论(0) 推荐(0) 编辑
摘要: 计时的几种方法,在虚拟机中不会出现问题,但是在真机测试中,会遇到这样一种情况: 在手机进行休眠状态后,原来的睡60秒时间,大约变成了睡7分钟左右才再执行.这一直让我很不解,也没有发现代码上有什么问题.后来发现别人也遇到了类似的问题. 发现常见的应用中,如游戏,播放器以及控制灯光显示中,都会有这种情况,后来通过找了一个资料才知道如果要定时执行的话,要用AlarmManager,这是闹钟服务,Android手机中必须要保证AlarmManager的时钟跟真实时间同步的.所以在 Android手机休眠状态下,AlarmManager时间是不会变慢的. 以下介绍AlarmManager的基本使用.Al 阅读全文
posted @ 2012-10-29 18:38 water0504 阅读(2017) 评论(0) 推荐(0) 编辑
摘要: A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application’s process is killed, the PendingIntent itself will remain usable from other processes that have been given it. If the cre 阅读全文
posted @ 2012-10-29 18:33 water0504 阅读(201) 评论(0) 推荐(0) 编辑
摘要: getApplicationContext() 返回应用的上下文,生命周期是整个应用,应用摧毁它才摧毁Activity.this的context 返回当前activity的上下文,属于activity ,activity 摧毁他就摧毁getBaseContext() 返回由构造函数指定或setBaseContext()设置的上下文this.getApplicationContext()取的是这个应 用程序的Context,Activity.this取的是这个Activity的Context,这两者的生命周期是不同 的,前者的生命周期是整个应用,后者的生命周期只是它所在的Activity。 阅读全文
posted @ 2012-10-29 18:30 water0504 阅读(162) 评论(0) 推荐(0) 编辑
摘要: This question is over a year old and is definitely long and complicated and the English language is difficult to understand. However, it still probably deserves some kind of answer.If I understand, you are basically asking for the difference between the different AndroidContextobjects. The main diff 阅读全文
posted @ 2012-10-29 17:47 water0504 阅读(1846) 评论(0) 推荐(0) 编辑
摘要: 在Android中,申请WakeLock可以让你的进程持续执行即使手机进入睡眠模式,比较实用的是比如后台有网络功能,可以保证操作持续进行.方法: 在操作之前加入PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); wakeLock.acquire(); 其中newWakeLock有两个参数,第一个参数定义了行为,第二个参数是调试的那个.. 阅读全文
posted @ 2012-10-29 17:42 water0504 阅读(521) 评论(0) 推荐(0) 编辑
摘要: PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);通过 Context.getSystemService().方法获取PowerManager实例。然后通过PowerManager的newWakeLock((int flags, Stringtag)来生成WakeLock实例。int Flags指示要获取哪种WakeLock,不同的Lock对cpu 、屏幕、键盘灯有不同影响。获取WakeLock实例后通过acquire()获取相应的锁,然后进行其他业务逻辑的操作,最后使用release()释放(释放 阅读全文
posted @ 2012-10-29 17:34 water0504 阅读(175) 评论(0) 推荐(0) 编辑
摘要: (1)[ 01-01 08:39:22.016 1228:0x4cd E/AndroidRuntime ]java.lang.Exception: WakeLock finalized while still held: My Tagat android.os.PowerManager$WakeLock.finalize(PowerManager.java:337)at dalvik.system.NativeStart.run(Native Method)WakeLock finalized while still held 表示 WakeLock对象在销毁时仍然被持有。因为我的Activi 阅读全文
posted @ 2012-10-29 17:33 water0504 阅读(449) 评论(0) 推荐(0) 编辑