android - Changing screen orientation makes login to begin again -
i have app login screen. when checking if login ok, show "loading" dialog
.
if change screen orientation, dialog
disappears , think check of login starts again, app crashes after that.
i've read solutions, can't works.
here code:
mainactivity.java
public void entrar(view view) { /* escondemos el teclado */ inputmethodmanager imm = (inputmethodmanager)getsystemservice( context.input_method_service); imm.hidesoftinputfromwindow(edittextusuario.getwindowtoken(), 0); /* comprobamos si hay conexión internet */ if(myapplication.isonline()) { loadingmaintask mywebfetch = new loadingmaintask(this); mywebfetch.execute(); } /* si no se dispone de conexión internet, mostramos un error */ else { myapplication.mostrarmensaje(this, r.string.error_conexion_titulo, r.string.error_conexion_mensaje); } } private class loadingmaintask extends asynctask<string, void, boolean> { private progressdialog dialog; private volatile boolean running = true; private mainactivity activity; tuplausuario tuplausuario = new tuplausuario(); private loadingmaintask(mainactivity activity) { this.activity = activity; context = activity; dialog = new progressdialog(context); dialog.setcancelable(true); dialog.setoncancellistener(new oncancellistener() { @override public void oncancel(dialoginterface dialog) { cancel(true); } }); } /** application context. */ private context context; @override protected void oncancelled() { running = false; } @override protected void onpreexecute() { this.dialog.setmessage(getstring(r.string.loading)); this.dialog.show(); } @override protected void onpostexecute(final boolean success) { if (dialog.isshowing()) { dialog.dismiss(); } if (success) { /* si el login no es correcto, mostramos un error por pantalla */ if (!tuplausuario.getok()) { myapplication.mostrarmensaje(activity, r.string.error_datos_login_titulo, tuplausuario.getmensaje()); } /* entrar */ else { intent intent = new intent(activity, tabsfacturasactivity.class); startactivity(intent); } } else { system.out.println("throw exception post"); myapplication.throwexception(activity); } } @override protected boolean doinbackground(final string... args) { try{ string usuario = string.valueof((edittextusuario).gettext()); string password = string.valueof((edittextpassword).gettext()); /* comprobar datos del login */ try { tuplausuario = myapplication.getdatosusuario(usuario, password, loginguardado); } catch (jsonexception e) { myapplication.throwexception(activity); e.printstacktrace(); } catch (illegalstateexception e) { myapplication.throwexception(activity); e.printstacktrace(); } catch (ioexception e) { myapplication.throwexception(activity); e.printstacktrace(); } /* si el login es correcto, nos guardamos su login, descargamos el resto * de información y entramos */ if (tuplausuario.getok()) { boolean rememberme = myapplication.getrememberme(); if (rememberme) { /* si el usuario ya estaba guardado, no hace falta volver guardarlo */ if(!loginguardado) { myapplication.guardarusuario(activity, usuario, password); } } } return true; } catch (exception e){ return false; } } }
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" ... > <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/styledindicators" android:configchanges="orientation" android:name="com.example.factorenergia.myapplication" > <activity android:name="com.example.factorenergia.mainactivity" android:label="@string/app_name" android:configchanges="orientation" android:theme="@style/apptheme" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> ... </application> </manifest>
try in manifest...
<activity android:name="your activity name" android:configchanges="keyboard|keyboardhidden|orientation|screenlayout|uimode|screensize|smallestscreensize" android:windowsoftinputmode="adjustpan"/>
Comments
Post a Comment