activity.runOnUiThread()內的run()方法沒有被執行

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

run()方法沒有執行,查找緣由,在原來,掉用runOnUiThread的activity,必定得是Activity對象,so,在使用以前,須要增長判讀:
if(activity instanceOf Activity){

}

參考連接


原文:java

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 }"
相關文章
相關標籤/搜索