android - Fix Can't create handler inside thread that has not called Looper.prepare() -


edit: did of stack overflow friends inside thread display video view inside of dialog in android freezes application me big in advance

this activity thread :

auto_bucket_tests_thread = new thread(new runnable()          {              @suppresswarnings("deprecation")             @override             public void run() {                  while(test_completed==false)                 {                     if(login.bucket_status==true && video_status==false)                     {                          new handler(looper.getmainlooper()).post(new runnable() {                              @override                             public void run() {                                 bucket_open_error();                              }                         });                     }                     else if(login.bucket_status==false && video_status==true)                     {                     videodialog.cancel();                        }                 }                 auto_bucket_tests_thread.stop();             }         });       }            protected void bucket_open_error() {         videodialog = new dialog(this);         videodialog.requestwindowfeature(window.feature_no_title);         videodialog.setcontentview(r.layout.videodialog);         videodialog.show();         windowmanager.layoutparams layout_params =new windowmanager.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content);         layout_params.copyfrom(videodialog.getwindow().getattributes());         layout_params.dimamount=0;         videodialog.getwindow().setattributes(layout_params);          final videoview video = (videoview)videodialog.findviewbyid(r.id.videoview_dialog);          uri uri = uri.parse("android.resource://"+getpackagename()+"/"+r.raw.doorsclosing);         video.setvideouri(uri);         video.start();         video.setoncompletionlistener(new mediaplayer.oncompletionlistener() {              public void oncompletion(mediaplayer mp) {                 video_status=true;                 video.start();                 //app_message.show();               }     }); 

you trying create handler thread. if u dont want handler communicate ui thread create different thread , not handler. if u want handler communicate ui thread u need pass looper constructor.

new handler(looper.getmainlooper());

edit: replace

runonuithread

with

new handler(looper.getmainlooper()).post

runonuithread activity method create handler , post runnable in ui thread, because youare running on thread (created new thread , ran it) cant post ui becuase new handler has no connection ui (hence didint call looper prepare exeception).


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -