Note that there are some explanatory texts on larger screens.

plurals
  1. POViewRoot$CalledFromWrongThreadException on android app
    primarykey
    data
    text
    <p>I have read some threads regarding this and I did already take steps to resolve it. I am using a handler (so that I don't update the UI on a separate thread) and so far I can't understand why this is still happening.</p> <pre><code>public class MyApp extends Activity implements OnClickListener, Runnable { private ViewSwitcher switcher; private static final int REFRESH_SCREEN = 1; private boolean isValid = false; private ProgressDialog dialog; private TextView errorMessage; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button)findViewById(R.id.button1); button.setOnClickListener(this); TextView errorMessage = (TextView)findViewById(R.id.txtErrorMessage); errorMessage.setVisibility(View.GONE); switcher = (ViewSwitcher) findViewById(R.id.profileSwitcher); } public void onClick(View v) { isValid = false; dialog = ProgressDialog.show(ConcentraApp.this, "", "Loading. Please wait...", true); Thread thread = new Thread(this); thread.start(); } public void run() { String username = ((TextView)findViewById(R.id.txtUsername)).getText().toString(); String password = ((TextView)findViewById(R.id.txtPassword)).getText().toString(); errorMessage = (TextView)findViewById(R.id.txtErrorMessage); errorMessage.setVisibility(View.GONE); /* ... contact web service and get response ..*/ try { /* get result from web service */ isValid = Boolean.parseBoolean(result); if(isValid) { handler.sendEmptyMessage(1); } else { handler.sendEmptyMessage(0); } } catch (Exception e) { handler.sendEmptyMessage(2); isValid = false; } } private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { if(msg.what == 1) { errorMessage.setVisibility(View.VISIBLE); errorMessage.setText("Correct login"); switcher.showNext(); } else if(msg.what == 0) { errorMessage.setVisibility(View.VISIBLE); errorMessage.setText("Invalid login"); } else { errorMessage.setVisibility(View.VISIBLE); errorMessage.setText("Internet error"); } dialog.dismiss(); } }; } </code></pre> <p>I am very new to this so I wouldn't be surprised if I'm missing something obvious. It works fine without the thread, but then the process dialog doesn't show.</p> <p>Many thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload