views:

43

answers:

0

I have an animated icon in the status bar which works at first, but after alittle bit it starts to mess up. it is set to switch between two icons every 2 seconds and works fine at first, but after alittle bit it starts to go fast. it will stay with one icon for about a second and then set the other icon, then right back to the first icon. I am not sure why it is doing this and how to fix it, can anyone help? my code is below

contentView.setImageViewResource(R.id.image, icn[level]);
           notification = new Notification(icn[level], msg, System.currentTimeMillis());
           notification.contentView = contentView;
           Intent notificationIntent = new Intent(this, SimpleService.class);
           PendingIntent contentIntent = PendingIntent.getActivity(this, REQUEST_CODE, notificationIntent, 0);
           notification.contentIntent = contentIntent;
           manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

           notification.flags |= Notification.FLAG_NO_CLEAR;
           notification.flags |= Notification.FLAG_ONGOING_EVENT;
           if (led)
            {
           notification.ledARGB = 0xFFff0000;
           notification.ledOnMS = 100;
           notification.ledOffMS = 100;
           notification.flags = Notification.FLAG_SHOW_LIGHTS;
             }                  
           manager.notify(NOTIFICATION_ID, notification);
           Thread thread = new Thread(this);
                thread.start();
       }
   }
   @Override
    public void run() {
      while (!stop){
            try {
                Thread.sleep(2000);

                handler.sendEmptyMessage(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
   }

    }

    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            if (show == 0) {
                notification.icon=cIcon;
                show = 1;
            } else {
                show = 0;
                notification.icon = icn[level];
            }
            if (!stop)
            {
                manager.notify(NOTIFICATION_ID, notification);
            }
            else if (stop)
            {
                manager.cancelAll();
            }
            else
            {
                notification.icon = icn[level];
            }


            super.handleMessage(msg);
        }

    };