Create multiple handler based on server response and manage there states

前端 未结 1 991
隐瞒了意图╮
隐瞒了意图╮ 2021-01-25 22:43

I want to create multiple handler and run-able when my app receive response from server.

The handlers can be maximum 4 and minimum 1.

Pr

相关标签:
1条回答
  • 2021-01-25 23:23

    If I correctly understand your code you need to replace

    handler.postDelayed(myRunnable, 5000); 
    

    with

    handler.postDelayed(this, 5000); 
    

    because myRunnable is the latest Runnable that you created. And all your handlers post it instead of themselfs.

    EDIT:
    You store in each handler it's number - index. You can add method

    void handleResponse(int index, Object someData)
    

    to your class, that creates handlers. After that each handler can call handleResponse(index, data) to notify about some changes.

    0 讨论(0)
提交回复
热议问题