I edited your second function code, I see that your code is a loop forever, because firstMethod calls secondMethod, and secondMethod calls a new firstMethod to start, and then the loop is forever. I deleted it and moved the ImageView code update to the UI thread, could you try the following:
class ThraedDemo { private void firstMethod() { Thread objThread = new Thread() { @Override public void run() { try { runOnUiThread(new Runnable() { public void run(){ ((ImageView)findViewById(R.id.ImageViewnumber)).setImageResource(nums[n]); } }); Thread.sleep(10000); Log.v("Thread","1111111111111111sleep"); } catch (InterruptedException ex) { System.out.println("interuped exception" + ex.getMessage()); } secondMethod(); } }; objThread.start(); } private void secondMethod() { Thread objThread2 = new Thread() { @Override public void run() { try { runOnUiThread(new Runnable() { public void run(){ ((ImageView)findViewById(R.id.ImageViewnumber)).setImageResource(nums[n+1]); } }); n++; Thread.sleep(10000); Log.v("Thread","22222222222 sleep"); } catch (InterruptedException ex) { System.out.println("interuped exception" + ex.getMessage()); } } }; objThread2.start(); } }
Khang Tran Dec 24 '15 at 3:54 2015-12-24 03:54
source share