不要使用Thread
应直接使用Handler与Runnable接口对象组合运行。
使用Thread会产生一些莫名其妙的问题,比如:壁纸预览时报错;壁纸设置时报错;壁纸设置后闪一下即消失变为默认静态壁纸;壁纸设置后停止运行但切换到待机状态再切回还是能运行的。
当壁纸设置后消失时,在DDMS中看到产生的异常信息类似:
01-13 03:04:53.734: INFO/DEBUG(1856): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-13 03:04:53.734: INFO/DEBUG(1856): Build fingerprint: \'hkcsl_cht/htc_bravo/bravo/bravo:2.2/FRF91/236241:user/release-keys\'
01-13 03:04:53.734: INFO/DEBUG(1856): pid: 2830, tid: 2867 >>> com.skyd.mantrawheel <<<
01-13 03:04:53.734: INFO/DEBUG(1856): signal 11 (SIGSEGV), fault addr deadbaad
01-13 03:04:53.734: INFO/DEBUG(1856): r0 00000000 r1 afd14699 r2 00000027 r3 00000074
01-13 03:04:53.734: INFO/DEBUG(1856): r4 afd42328 r5 00000000 r6 00000000 r7 0000a000
01-13 03:04:53.734: INFO/DEBUG(1856): r8 00000000 r9 48533900 10 485338d8 fp 000001e0
01-13 03:04:53.734: INFO/DEBUG(1856): ip 00001730 sp 48533590 lr deadbaad pc afd11cf0 cpsr 60000030
01-13 03:04:53.734: INFO/DEBUG(1856): d0 643a64696f72646e d1 6472656767756265
01-13 03:04:53.734: INFO/DEBUG(1856): d2 062b818b0627c18a d3 0633418d062f818c
01-13 03:04:53.734: INFO/DEBUG(1856): d4 0000018f0000018f d5 0000018f0000018f
01-13 03:04:53.734: INFO/DEBUG(1856): d6 be6659913f797051 d7 0000000043c24000
01-13 03:04:53.734: INFO/DEBUG(1856): d8 000001e000000000 d9 40790000000000a0
01-13 03:04:53.734: INFO/DEBUG(1856): d10 3fd34413509f79fe d11 bfe3441350ad386e
01-13 03:04:53.734: INFO/DEBUG(1856): d12 3ddb7cdfd9d7bdbb d13 0000000000000000
01-13 03:04:53.734: INFO/DEBUG(1856): d14 0000000000000000 d15 0000000000000000
01-13 03:04:53.734: INFO/DEBUG(1856): d16 018e41d4018e7b6a d17 018dcea8018e083e
01-13 03:04:53.734: INFO/DEBUG(1856): d18 018ed1b2018dd842 d19 0190c492018fcb22
01-13 03:04:53.734: INFO/DEBUG(1856): d20 0000000000000000 d21 0000000000000000
01-13 03:04:53.734: INFO/DEBUG(1856): d22 0000018f0000018f d23 0000018f0000018f
01-13 03:04:53.744: INFO/DEBUG(1856): d24 0000018f0000018f d25 0000018f0000018f
01-13 03:04:53.744: INFO/DEBUG(1856): d26 ffff19a8ffff19a8 d27 ffff19a8ffff19a8
01-13 03:04:53.744: INFO/DEBUG(1856): d28 0003e5c00003e5c0 d29 0003e5c00003e5c0
01-13 03:04:53.744: INFO/DEBUG(1856): d30 0001000000010000 d31 0001000000010000
01-13 03:04:53.744: INFO/DEBUG(1856): scr 60000012
01-13 03:04:53.814: INFO/DEBUG(1856): #00 pc 00011cf0 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): #01 pc 0000be62 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): #02 pc 0000cdc2 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): #03 pc 000008d8 /system/lib/libstdc++.so
01-13 03:04:53.814: INFO/DEBUG(1856): #04 pc 0004d3f8 /system/lib/libskia.so
01-13 03:04:53.814: INFO/DEBUG(1856): #05 pc 0006ad50 /system/lib/libskia.so
01-13 03:04:53.814: INFO/DEBUG(1856): #06 pc 0006d5b0 /system/lib/libskia.so
01-13 03:04:53.814: INFO/DEBUG(1856): code around pc:
01-13 03:04:53.814: INFO/DEBUG(1856): afd11cd0 2d00682d e029d1fb b12b68db c05cf8df
01-13 03:04:53.814: INFO/DEBUG(1856): afd11ce0 f8442001 4798000c e054f8df 26002227
01-13 03:04:53.814: INFO/DEBUG(1856): afd11cf0 2000f88e eee4f7fb f7fd2106 f04fe802
01-13 03:04:53.814: INFO/DEBUG(1856): afd11d00 91035180 460aa901 96012006 f7fc9602
01-13 03:04:53.814: INFO/DEBUG(1856): afd11d10 a905eb88 20024632 eb92f7fc eed0f7fb
01-13 03:04:53.814: INFO/DEBUG(1856): code around lr:
01-13 03:04:53.814: INFO/DEBUG(1856): deadba8c ffffffff ffffffff ffffffff ffffffff
01-13 03:04:53.814: INFO/DEBUG(1856): deadba9c ffffffff ffffffff ffffffff ffffffff
01-13 03:04:53.814: INFO/DEBUG(1856): deadbaac ffffffff ffffffff ffffffff ffffffff
01-13 03:04:53.814: INFO/DEBUG(1856): deadbabc ffffffff ffffffff ffffffff ffffffff
01-13 03:04:53.814: INFO/DEBUG(1856): deadbacc ffffffff ffffffff ffffffff ffffffff
01-13 03:04:53.814: INFO/DEBUG(1856): stack:
01-13 03:04:53.814: INFO/DEBUG(1856): 48533550 00000015
01-13 03:04:53.814: INFO/DEBUG(1856): 48533554 afd146c9 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 48533558 afd425a0 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 4853355c afd4254c /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 48533560 00000000
01-13 03:04:53.814: INFO/DEBUG(1856): 48533564 afd156e3 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 48533568 afd14699 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 4853356c afd14699 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 48533570 00000074
01-13 03:04:53.814: INFO/DEBUG(1856): 48533574 afd42328 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 48533578 00000000
01-13 03:04:53.814: INFO/DEBUG(1856): 4853357c 485335a4
01-13 03:04:53.814: INFO/DEBUG(1856): 48533580 0000a000 [heap]
01-13 03:04:53.814: INFO/DEBUG(1856): 48533584 afd1493b /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 48533588 df002777
01-13 03:04:53.814: INFO/DEBUG(1856): 4853358c e3a070ad
01-13 03:04:53.814: INFO/DEBUG(1856): #00 48533590 afd438e4 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 48533594 afd1040c /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 48533598 afd42328 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 4853359c 48e40628
01-13 03:04:53.814: INFO/DEBUG(1856): 485335a0 48e40628
01-13 03:04:53.814: INFO/DEBUG(1856): 485335a4 fffffbdf
01-13 03:04:53.814: INFO/DEBUG(1856): 485335a8 afd42328 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 485335ac afd4372c /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): 485335b0 48e40628
01-13 03:04:53.814: INFO/DEBUG(1856): 485335b4 afd0be67 /system/lib/libc.so
01-13 03:04:53.814: INFO/DEBUG(1856): #01 485335b8 48e40660
01-13 03:04:53.814: INFO/DEBUG(1856): 485335bc 00142180 [heap]
01-13 03:04:53.814: INFO/DEBUG(1856): 485335c0 00001404
01-13 03:04:53.814: INFO/DEBUG(1856): 485335c4 485338b0
01-13 03:04:53.814: INFO/DEBUG(1856): 485335c8 00000000
01-13 03:04:53.814: INFO/DEBUG(1856): 485335cc 48e40628
01-13 03:04:53.814: INFO/DEBUG(1856): 485335d0 48e40628
01-13 03:04:53.814: INFO/DEBUG(1856): 485335d4 00000000
01-13 03:04:53.814: INFO/DEBUG(1856): 485335d8 485338b0
01-13 03:04:53.814: INFO/DEBUG(1856): 485335dc afd0cdc5 /system/lib/libc.so
目前经过多次尝试仍未探知具体出错的地方。
可以指定一个Activity为动态壁纸设置界面
需在壁纸设置文件中这样指定:
<?xml version="1.0" encoding="utf-8"?>
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
android:author="@+string/author"
android:description="@string/description"
android:thumbnail="@drawable/mani1"
android:settingsActivity="com.skyd.mantrawheel.Main"
/>
并且该Activity必须在AndroidManifest.xml中这样注册:
<activity android:name=".Main" android:label="@string/app_name" android:exported="true"></activity>
最好指定uses-feature标记
在AndroidManifest.xml中指定如下代码会使程序在市场中对不支持动态壁纸功能的用户隐藏:
<uses-feature android:name="android.software.live_wallpaper" />
必须在onCreate(SurfaceHolder surfaceHolder)中指定setTouchEventsEnabled(true);
如果你放在onSurfaceCreated(SurfaceHolder holder)中指定,你会很郁闷地发现动态壁纸在2.1版本的系统中可以运行,2.2版本却报错。
参考资料
http://www.androiddevblog.net/android/creating-android-live-wallpaper#
http://code.google.com/p/krvarma-android-samples/source/browse/trunk/patternwallpaper/?r=80