activity.runOnUiThread(new Runnable() {
                public void run()
                {
                    Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
                }
            });

run()方法没有执行,查找原因,在原来,掉用runOnUiThread的activity,一定得是Activity对象,so,在使用之前,需要增加判读:
if(activity instanceOf Activity){

}

参考链接


原文:

It doesn't always work, you have to be sure that what you are casting is
effectively an Activity or you'll have a ClassCastException. To do that you can do
"if(context instanceOf Activity){ // proceed to cast }"

 

 

相关文章:

  • 2021-06-07
  • 2021-12-06
  • 2021-12-30
  • 2021-12-09
  • 2021-12-09
  • 2021-09-12
  • 2022-01-07
猜你喜欢
  • 2021-07-08
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
相关资源
相似解决方案