You must call startActivity (intent) from the user interface thread. You can simply create a new method, for example:
public void startActivityFromMainThread(){
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Intent intent = new Intent (MainActivity.this, NewMainActivity.class);
startActivity(intent);
}
});
}
Looper.getMainLooper() , .
:
new Thread(new Runnable() {
public void run() {
progressBar.setMax(100);
progressStatus = 0;
while (progressStatus < 100) {
progressStatus += 5;
handler.post(new Runnable() {
@Override
public void run() {
progressBar.setProgress(progressStatus);
textView.setText(progressStatus + "/"
+ progressBar.getMax());
}
});
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
startActivityFromMainThread();
}
}).start();