Trying to show ProgressDialog, but getting:
Can’t create handler inside thread that has not called Looper.prepare().
Here is my code:
public class SocketThread implements Runnable {
BufferedReader in;
private ProgressDialog dialog;
public void run()
{
socket = null;
while (true)
{
// Loop until connected to server
while (socket == null){
dialog = new ProgressDialog(getApplicationContext());
dialog.setMessage("Connecting to " + gatewayString);
dialog.setIndeterminate(true);
dialog.setCancelable(true);
AdvancedMultipleSeriesGraph.this.runOnUiThread(new Runnable() {
public void run() {
dialog.show();
}
});
Is it possible to fix?
you can use an Handler and use
Handler.post(Runnable)or, if you have an activity context you can useActivity.runOnUiThread(Runnable action)