Android thread problem, why ui still blocks when i have used a worker thread? Android thread problem, why ui still blocks when i have used a worker thread? multithreading multithreading

Android thread problem, why ui still blocks when i have used a worker thread?


You need to call start() not run().

public void onClick(View v) {      mBackground.start();  //Start will spawn the Thread and then call it's run method.}

By calling run() in the main thread, you are blocking there just like any normal method call.


try this code

private void showProgrssBar(){pLayout.setVisibility(View.VISIBLE);final StringBuffer s=new StringBuffer();final Thread progressThread=new Thread(){    @Override    public void run(){            while(CreateVideoService.processingFrame>1) {                 inc=100-((CreateVideoService.processingFrame*100)/(CreateVideoService.numberofRecordedFrames));                 if(s.length()>0)                 s.delete(0, s.length());                 s.append("Processing... ").append(inc).append("%");                 progressBarHandler.post(new Runnable() {                    @Override                    public void run() {                        // TODO Auto-generated method stub                        progressBar.setProgress(inc);                        textProgrs.setText(s);                     }                });                 //progressBar.setProgress(100-inc);                 try {                     // Sleep for 5 seconds                     Thread.sleep(200);                 } catch (InterruptedException e) {                     //Log.d("TAG", "sleep failure");                 }            }            layoutHandler.post(new Runnable() {                @Override                public void run() {                    // TODO Auto-generated method stub                    pLayout.setVisibility(View.GONE);                }            });    }};progressThread.start();}