Note that there are some explanatory texts on larger screens.

plurals
  1. PODon't reset AsyncTask and use onSaveInstanceState
    primarykey
    data
    text
    <p>In my <code>MainActivity</code> I have a login <code>view</code>. While I check for username and password in <code>AsyncTask</code>, I show a <code>ProgressDialog</code>. </p> <p>I asked in another question how to not reseting <code>AsyncTask</code>and I achieved it with <code>AndroidManifest.xml</code>, but I need to save username and password for not to be removed if I change orientation, but <code>onSaveInstanceState</code> and <code>onRestoreInstanceState</code> methods are not being called.</p> <p>I think the problem must be related to <code>android:configChanges</code>in <code>AndroidManifest</code>. Can you help me?</p> <p><strong>Here is my code:</strong></p> <p><strong>MainActivity.java</strong></p> <pre><code>//Method called when login Button is pressed 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 a Internet */ if(myApplication.isOnline()) { LoadingMainTask myWebFetch = new LoadingMainTask(this); myWebFetch.execute(); } /* Si no se dispone de conexión a Internet, mostramos un error */ else { myApplication.mostrarMensaje(this, R.string.error_conexion_titulo, R.string.error_conexion_mensaje); } } private class LoadingMainTask extends AsyncTask&lt;String, Void, Boolean&gt; { 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) { while (running) { try{ String usuario = String.valueOf((editTextUsuario).getText()); String password = String.valueOf((editTextPassword).getText()); /* Check login */ } return true; } catch (Exception e){ return false; } } return null; } } </code></pre> <p><strong>AndroidManifest.xml</strong></p> <pre><code>&lt;application android:allowBackup="true" //... android:configChanges="orientation" &gt; &lt;activity //This next two lines are what I was said to use and that works. Other answers were not useful android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:windowSoftInputMode="adjustPan" android:theme="@style/AppTheme" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; </code></pre>
    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