Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e4ce0fc authored by Tom O'Neill's avatar Tom O'Neill Committed by Android (Google) Code Review
Browse files

Merge "Update Notepad tutorial documentation to match code"

parents 1a8eec69 c88f13e0
Loading
Loading
Loading
Loading
+55 −55
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public boolean onCreateContextMenu(Menu menu, View v
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.add(0, DELETE_ID, 0, R.string.menu_delete);
}</pre>
    <p>The <code>onCreateContextMenu()</code> callback some passes other information in addition to the Menu object, 
    <p>The <code>onCreateContextMenu()</code> callback passes some other information in addition to the Menu object,
    such as the View that has been triggered for the menu and
    an extra object that may contain additional information about the object selected. However, we don't care about
    these here, because we only have one kind of object in the Activity that uses context menus. In the next
@@ -613,7 +613,7 @@ protected void onCreate(Bundle savedInstanceState) {
    <code>AndroidManifest.xml</code> file and look at the source (use the
    <code>AndroidManifest.xml</code> tab in the eclipse editor to see the source code directly).
    Then edit the file as follows:<br>
    <code>&lt;activity android:name=".NoteEdit"&gt;&lt;/activity&gt;</code><br><br>
    <code>&lt;activity android:name=".NoteEdit" /&gt;</code><br><br>
    This should be placed just below the line that reads:<br>
    <code>&lt;/activity&gt;</code> for the <code>.Notepadv2</code> activity.</p>

+46 −37
Original line number Diff line number Diff line
@@ -87,8 +87,8 @@ if (body != null) {
        </pre>
        with this:
        <pre>
        mRowId = savedInstanceState != null ? savedInstanceState.getLong(NotesDbAdapter.KEY_ROWID) 
                                            : null;
        mRowId = (savedInstanceState == null) ? null :
            (Long) savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);
        if (mRowId == null) {
            Bundle extras = getIntent().getExtras();
            mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
@@ -102,6 +102,11 @@ if (body != null) {
      provided by the <code>savedInstanceState</code>. This is a ternary operator shorthand
      to safely either use the value or null if it is not present.
    </li>
    <li>
      Note the use of <code>Bundle.getSerializable()</code> instead of
      <code>Bundle.getLong()</code>.  The latter encoding returns a <code>long</code> primitive and
      so can not be used to represent the case when <code>mRowId</code> is <code>null</code>.
    </li>
  </ol>

<h2>Step 4</h2>
@@ -141,8 +146,8 @@ mBodyText = (EditText) findViewById(R.id.body);

Button confirmButton = (Button) findViewById(R.id.confirm);

mRowId = savedInstanceState != null ? savedInstanceState.getLong(NotesDbAdapter.KEY_ROWID) 
                                    : null;
mRowId = (savedInstanceState == null) ? null :
    (Long) savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);
if (mRowId == null) {
    Bundle extras = getIntent().getExtras();
    mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
@@ -241,8 +246,10 @@ and populate the View elements with them.</p>
    &#64;Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
        saveState();
        outState.putSerializable(NotesDbAdapter.KEY_ROWID, mRowId);
    }</pre>
    <p>We'll define <code>saveState()</code> next.</p>
    </li>
    <li><code>
      onPause()</code>:
@@ -252,7 +259,6 @@ and populate the View elements with them.</p>
        super.onPause();
        saveState();
    }</pre>
    <p>We'll define <code>saveState()</code> next.</p>
    </li>
    <li><code>
      onResume()</code>:
@@ -264,6 +270,10 @@ and populate the View elements with them.</p>
    }</pre>
    </li>
  </ol>
<p>Note that <code>saveState()</code> must be called in both <code>onSaveInstanceState()</code>
and <code>onPause()</code> to ensure that the data is saved.  This is because there is no
guarantee that <code>onSaveInstanceState()</code> will be called and because when it <em>is</em>
called, it is called before <code>onPause()</code>.</p>


<h2 style="clear:right;">Step 8</h2>
@@ -301,8 +311,7 @@ database.</p>
    necessary. The resulting method should look like this:</p>
<pre>
&#64;Override
protected void onActivityResult(int requestCode, int resultCode, 
                                Intent intent) {
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    fillData();
}</pre>