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){

}

參考鏈接


原文:

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 }"

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM