This Handler class should be static or leaks might occur problem

Asked 2 years ago, Updated 2 years ago, 20 views

This Handler class should be static or leaks might occur, and the habdler is not working, so I am asking you a question. There was a problem using the switch using the sm-x board.

final Handler handler = new Handler() {
      @Override
      public void handleMessage(Message msg) {
         switch (cnt){
         case 1:
            if (msg.arg1 == 1){
                mDriver.setCursorVisible(0);
                when =0;
            }
            cnt++;
            break;
         case 2:
            if (msg.arg1 == 1){
                mDriver.setCursorVisible(0);
                when =1;
            }
            cnt++;
            break;
         case 3:
            if (msg.arg1 == 1)
               mDriver.setCursorShift(1);
            cnt++;
            break;
         case 4:
            if (msg.arg1 == 1)
               mDriver.setCursorShift(0);
            cnt++;
            break;
         case 5:
            if (msg.arg1 == 1)

            cnt = 1;
            break;
         }
      }
   }

;

android java

2022-09-21 15:35

1 Answers

You can use the class after using the public class or the public static class instead of using the handler as an anonymous class. If you look at the attached code, there's an anonymous class, and if you use it, you'll have a reference to this, so even if the original class is done, the reference will still remain and won't disappear. Handler is likely to be running for a very long time, so it seems to be issuing this warning.


2022-09-21 15:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.