Android “Only the original thread that created a view hierarchy can touch its views.”

后端 未结 28 3271
鱼传尺愫
鱼传尺愫 2020-11-21 04:44

I\'ve built a simple music player in Android. The view for each song contains a SeekBar, implemented like this:

public class Song extends Activity implement         


        
28条回答
  •  遇见更好的自我
    2020-11-21 05:21

    I solved this by putting runOnUiThread( new Runnable(){ .. inside run():

    thread = new Thread(){
            @Override
            public void run() {
                try {
                    synchronized (this) {
                        wait(5000);
    
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                dbloadingInfo.setVisibility(View.VISIBLE);
                                bar.setVisibility(View.INVISIBLE);
                                loadingText.setVisibility(View.INVISIBLE);
                            }
                        });
    
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Intent mainActivity = new Intent(getApplicationContext(),MainActivity.class);
                startActivity(mainActivity);
            };
        };  
        thread.start();
    

提交回复
热议问题