i am new to java & trying to create a live wallpaper that contains some timer elements, but i get some strange behaviors all the time:
1. is it possible to clear last canvas after refreshing it with new time? my code adds the new data on top of the old. is it okay to add black background (canvas.drawColor(0xFF000000); ) to cover it? is this going to cause some memory issues?
2. the app works fine in the wallpaper preview, but crushes after clicking "set wallpaper", restarts than & works fine again ..
i hope somebody has an idea...
THANKS!!
tom
my code:
Using java Syntax Highlighting
- public class myClock extends WallpaperService {
- @Override
- public Engine onCreateEngine() {
- return new wp();
- }
- class wp extends Engine{
- public Paint seconds;
- public Canvas canvas;
- private Handler mHandler = new Handler();
- @Override
- public void onSurfaceCreated(SurfaceHolder arg0)
- {
- mHandler.postDelayed(mUpdateTimeTask, 10);
- }
- private Runnable mUpdateTimeTask = new Runnable()
- {
- @Override
- public void run()
- {
- canvas = getSurfaceHolder().lockCanvas();
- seconds = new Paint();
- seconds.setColor(0xFF666666);
- seconds.setTextSize(50);
- Date date = new Date();
- canvas.drawText(Double.toString(date.getSeconds()), 10 , 100, seconds);
- mHandler.postDelayed(this, 1000);
- getSurfaceHolder().unlockCanvasAndPost(canvas);
- }
- };
- }
- }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

