1
내 스레드에서 만든 "첫 번째"토스트 만 보이고 다른 토스트는 보이지 않는 이유는 무엇입니까?내 스레드에서 실행될 때 토익이 표시되는 것을 무시합니다.
public class BannerExample extends Activity {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast toast = Toast.makeText(this, "first toast", Toast.LENGTH_SHORT);
toast.show();
new MyThread(this).start();
}
class MyThread extends Thread {
private Context context;
public MyThread(Context context) {
this.context = context;
}
public void run() {
Looper.prepare(); // An exception told me to add this - i have no clue why
for (int i = 0; i < 3; i++) {
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Toast toast = Toast.makeText(context, i + "whoho", Toast.LENGTH_SHORT);
toast.show();
}
}
}
}
최고 생성자, 덕분에
getBaseContext
에서 컨텍스트를 전달합니다! – corgrath