Note that there are some explanatory texts on larger screens.

plurals
  1. POOut of memory, showing AlertDialog and making changes in orientation
    text
    copied!<p>I have an activity containing two imagebuttons. If the user clicks back an alertDialog is shown. While the alert is shown, if the orientation is changed back and forth a few times the application crashes with this message:</p> <pre><code>ERROR/dalvikvm-heap(10988): 3363556-byte external allocation too large for this process. ERROR/dalvikvm(10988): Out of memory: Heap Size=4935KB, Allocated=2594KB, Bitmap Size=19579KB ERROR/GraphicsJNI(10988): VM won't let us allocate 3363556 bytes </code></pre> <p>If the AlertDialog is not there, the application doesn't crash.</p> <pre><code>public class StartPageView extends Activity implements OnClickListener, android.content.DialogInterface.OnClickListener { private static final String TAG = "StartPageView"; private ImageButton vacButton; private ImageButton sickButton; private AlertDialog alert; private static boolean alertDismissedByLifeCycle = false; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.startpage); vacButton = (ImageButton)findViewById(R.id.gotovac_btn); vacButton.setOnClickListener(this); sickButton = (ImageButton)findViewById(R.id.gotosick_btn); sickButton.setOnClickListener(this); if(alertDismissedByLifeCycle) { alertDismissedByLifeCycle = false; showAlert(); } } @Override protected void onStop() { if(alert != null &amp;&amp; alert.isShowing()) { alertDismissedByLifeCycle = true; alert.dismiss(); } super.onStop(); } //GO TO VACATION VIEW OR SICK VIEW //user clicked on vacView button or sickView button @Override public void onClick(View v) { if(v.equals(this.vacButton)) { Intent i = new Intent(this, VacationLeaveView.class); startActivity(i); } if(v.equals(this.sickButton)) { Intent i = new Intent(this, SickLeaveView.class); startActivity(i); } } //LOG OUT //user pressed the back button @Override public void onBackPressed() { showAlert(); } //OnClickListener for logging out warning @Override public void onClick(DialogInterface dialog, int which) { if(which == DialogInterface.BUTTON_POSITIVE) { MainController.getInstance().clearAllChildren(); dialog.cancel(); this.finish(); } else dialog.cancel(); } //DIALOG private void showAlert() { if(alert == null) { AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); alertDialog.setMessage("Vill du logga ut från förskoleportalen?"); alertDialog.setPositiveButton("Ja", this); alertDialog.setNegativeButton("Nej", this); alert = alertDialog.create(); // Title for AlertDialog alert.setTitle("Logga ut"); } alert.show(); } </code></pre>
 

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