1
I have an app that logs a teacher into a webservice and right after logging in it inserts the user into the android database. If the result is different from null, I want you to call the Activity menu. However my application is closing. Follow the code.
public class Login extends Activity {
ProfessorWS professorWS = new ProfessorWS();
Professor professor = new Professor();
ProfessorDAO professorDAO = new ProfessorDAO(this);
private EditText edUsuario, edSenha;
private Handler handler = new Handler();
Intent intent = new Intent(this,Menu.class);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
edUsuario = (EditText) findViewById(R.id.edUsuario);
edSenha = (EditText) findViewById(R.id.edSenha);
}
public void btEntrarOnClick (View view){
String msg = getString(R.string.dlg_msg);
String titulo = getString(R.string.dlg_titulo);
final ProgressDialog dialog = ProgressDialog.show(this, titulo, msg);
new Thread(new Runnable() {
@Override
public void run() {
try {
LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();
params.put("user", edUsuario.getText().toString());
params.put("senha", edSenha.getText().toString());
professor = professorWS.buscarProfessor(params);
professorDAO.insereProfessor(professor);
handler.post(new Runnable() {
@Override
public void run() {
if (professor.getCodProfessor() != null){ //
Toast t = Toast.makeText(getBaseContext(), "Código pro: " + professor.getCodProfessor(), Toast.LENGTH_SHORT);
t.show();
}else{
Toast t = Toast.makeText(getBaseContext(), "Código professor nao encotrado " , Toast.LENGTH_SHORT);
t.show();
}
}
});
} catch (Exception e) {
} finally {
dialog.dismiss();
}
}
}).start();
}
usually closes so because it gave some error, via rule some exception that was not picked up, checks the logcat, will probably have a stacktrace there
– Neuber Oliveira
My question is whether you can call the other Activity inside runOnUiThread(new Runnable() { @Override public void run() {
– alannrs
But have you tried it? Did you make a mistake? As far as I know
run()
already wheel within its "main" thead, then it should work.– Neuber Oliveira
Yes, you made the following mistake
– alannrs
ActivityThread.handleLaunchActivit
– alannrs
Does Progressdialog.show work? I always use the dialog variable show method. Check if it works. You may also need to place the show inside a separate thread. Then you use runOnUiThread.
– Giuliana Bezerra