Hi,

I don't know what the issue is with your animation but your solution
is going to be very very expensive. Calling setWallpaper() writes the
image into the /data partition and Home then loads that image. This
means that every two seconds you are doing one write + one read of a
rather large image. This is going to kill the battery.

On Mon, Nov 17, 2008 at 4:56 AM, Kakyoin <[EMAIL PROTECTED]> wrote:
>
> This is my Service.
>
> It's a simple service which use Handler to invoke "setWallpaper()"
> every 2 seconds.
> [code]
> package com.mseer.testservice;
>
> import java.io.IOException;
> import java.io.InputStream;
>
> import android.app.Service;
> import android.content.Context;
> import android.content.Intent;
> import android.graphics.Bitmap;
> import android.graphics.BitmapFactory;
> import android.os.Handler;
> import android.os.IBinder;
> import android.os.Message;
> import android.util.Log;
>
> public class MyService extends Service{
>
>  public IBinder onBind(Intent intent) {
>    return null;
>  }
>
>
>  protected static Service sv;
>  protected static InputStream bg01, bg02, bg03, bg04, bg05, bg06;
>
>  protected static int index=0;
>
>  protected static final int SECONDPASSED = 0x1234;
>
>  protected boolean running = false;
>
>  Thread counterThread = null;
>
>  static Handler myWallpaperHandler = new Handler(){
>       public void handleMessage(Message msg) {
>            switch (msg.what) {
>                 case MyService.SECONDPASSED:
>
>                     updateWallpaper();
>
>                      break;
>            }
>            super.handleMessage(msg);
>       }
>  };
>
>
>
>
>
>  protected static void updateWallpaper(){
>
>      try {
>            if(index==0){
>                sv.setWallpaper(bg01);
>            }else if(index==1){
>                sv.setWallpaper(bg02);
>            }else if(index==2){
>                sv.setWallpaper(bg03);
>            }else if(index==3){
>                sv.setWallpaper(bg04);
>            }else if(index==4){
>                sv.setWallpaper(bg05);
>            }else if(index==5){
>                sv.setWallpaper(bg06);
>            }
>
>            index++;
>            if(index>5){
>                index = 0;
>            }
>
>
>        } catch (IOException e) {
>
>            e.printStackTrace();
>        }
>
>
>
>
>  }
>
>
>
>  public void onCreate(){
>      sv = this;
>      super.onCreate();
>      running = true;
>      bg01 = sv.getResources().openRawResource(R.drawable.night01w);
>      bg02 = sv.getResources().openRawResource(R.drawable.night02w);
>      bg03 = sv.getResources().openRawResource(R.drawable.night03w);
>      bg04 = sv.getResources().openRawResource(R.drawable.night04w);
>      bg05 = sv.getResources().openRawResource(R.drawable.night05w);
>      bg06 = sv.getResources().openRawResource(R.drawable.night06w);
>
>      this.counterThread = new Thread(new secondCountDownRunner());
>      this.counterThread.start();
>
>  }
>
>  public void onDestroy() {
>    super.onDestroy();
>    running = false;
>    counterThread.interrupt();
>  }
>
>
> }
>
>
>
> class secondCountDownRunner implements Runnable{
>    public void run() {
>         while(!Thread.currentThread().isInterrupted()){
>              Message m = new Message();
>              m.what = MyService.SECONDPASSED;
>              MyService.myWallpaperHandler.sendMessage(m);
>              try {
>                   Thread.sleep(2000);
>              } catch (InterruptedException e) {
>                   Thread.currentThread().interrupt();
>              }
>         }
>    }
> }[/code]My problem:
>
> The wallpaper changes for 4-5 frames, then stopped...
>
>
> Solutions I've tried:
>
> 1. I tried Logging like this:
>
>
> [code]if(index==0){
>                Log.e("BM WALLPAPER","Wallpaper set to WP1 | " +
> bg01);
>                sv.setWallpaper(bg01);
>            }else if(index==1){
>                Log.e("BM WALLPAPER","Wallpaper set to WP2 | "  +
> bg02);
>                sv.setWallpaper(bg02);
> // and so on...
> [/code]And I can still see the Log message every 2 seconds (but the
> wallpaper dont change anymore)
>
>
>
> 2. I tried creating the InputStream every cycle. It works. But it
> greatly slow down the phone to an unacceptable level.
>
> [code]if(index==0){
>                              bg01 = sv.getResources().openRawResource
> (R.drawable.night01w);
>                sv.setWallpaper(bg01);
>            }else if(index==1){
>                                bg02 = sv.getResources
> ().openRawResource(R.drawable.night02w);
>                sv.setWallpaper(bg02);
> // and so on...[/code]3. I've tried all of the above solutions but use
> setWallpaper(Bitmap); instead. The result is even slower...
>
>
>
> My requests to experts in this forum:
> 1. I wonder why my wallpaper animated for only 4-5 frames, then
> stopped. (using the first code snippet posted above)
>
> 2. If anyone happen to know how to efficiently create an animated
> wallpaper, please let me know.
>
>
> Thank you in advance. =)
>
> >
>



-- 
Romain Guy
www.curious-creature.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to