Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you pressed "home" button, your activity goes to <code>onPause()</code>.</p> <p>So I personally recommend you to override the <code>onPause()</code> method which can not only handle the "home" button pressed but also other circumstances.</p> <p>In your case, it is only <code>onPause()</code> and <code>onResume()</code> related, so you can try put the state into <code>SharedPreferences</code> or Internal/External storage.</p> <p>say:</p> <p>in your <code>onPause()</code> method, do something like:</p> <pre><code>// Use Shared Preferences to save data SharedPreferences previewSizePref = getSharedPreferences("PREF",MODE_PRIVATE); SharedPreferences.Editor prefEditor = previewSizePref.edit(); prefEditor.putInt("x", somethingA); prefEditor.putInt("y", somethingB); prefEditor.commit(); </code></pre> <p>and in your <code>onResume()</code>, retrieve the saved data like:</p> <pre><code>SharedPreferences previewSizePref = getSharedPreferences("PREF",MODE_PRIVATE); if (previewSizePref.contains("x") &amp;&amp; previewSizePref.contains("y")) { //your saved data exists, do something } else { // handle the circumstances that the saved data doesn't exist } </code></pre> <p>For saving state in <code>onPause()</code> and restore in <code>onResume()</code> you can have a look at this answer:</p> <p><a href="https://stackoverflow.com/questions/8410259/saving-activity-state-in-the-onpause">Saving Activity State in the onPause</a></p> <p>And for SharedPreferences, you can have a look at API document: <a href="http://developer.android.com/guide/topics/data/data-storage.html#pref" rel="nofollow noreferrer">Data Storage - Shared Preferences</a></p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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