Android, Handler messaging

泪湿孤枕 提交于 2019-12-04 05:52:42

You must get the data from the Message (as Bundle then as int) you have sent in the handler you do:

Handler seconds=new Handler() { 
    @Override 
    public void handleMessage(Message msg) { 
      int sentInt = msg.getData().getInt("what");
      bar.incrementProgressBy(5); 
       tView1.setText("r:"+Integer.toString(sentInt));
    } 
  }; 

You need to extract the message in the same way you got it:

public void handleMessage(Message msg) { 
  bar.incrementProgressBy(5); 
  Bundle data = msg.getData();
  tView1.setText("r:"+data.getInt("what"));
} 

Sorry for not clarifying that in the previous answer...

P.S. I ignored checking for null for simplicity, but you should check if data is null...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!