Home | History | Annotate | Download | only in notepad

Lines Matching full:code

25 <p>Import <code>Notepadv3</code> into Eclipse. If you see an error about
26 <code>AndroidManifest.xml,</code> or some problems related to an Android zip
38 <li>Remove the code in <code>NoteEdit</code> that parses the title and body
40 <p>Instead, we are going to use the <code>DBHelper</code> class
42 NoteEdit Activity is a <code>mRowId</code> (but only if we are editing, if creating we pass
49 the <code>extras</code> Bundle, which we were using to set the title
63 <p>Create a class field for a <code>NotesDbAdapter</code> at the top of the NoteEdit class:</p>
65 <p>Also add an instance of <code>NotesDbAdapter</code> in the
66 <code>onCreate()</code> method (right below the <code>super.onCreate()</code> call):</p>
73 <p>In <code>NoteEdit</code>, we need to check the <var>savedInstanceState</var> for the
74 <code>mRowId</code>, in case the note
79 Replace the code that currently initializes the <code>mRowId</code>:<br>
100 Note the null check for <code>savedInstanceState</code>, and we still need to load up
101 <code>mRowId</code> from the <code>extras</code> Bundle if it is not
102 provided by the <code>savedInstanceState</code>. This is a ternary operator shorthand
106 Note the use of <code>Bundle.getSerializable()</code> instead of
107 <code>Bundle.getLong()</code>. The latter encoding returns a <code>long</code> primitive and
108 so can not be used to represent the case when <code>mRowId</code> is <code>null</code>.
114 <p>Next, we need to populate the fields based on the <code>mRowId</code> if we
117 <p>This goes before the <code>confirmButton.setOnClickListener()</code> line.
123 <code>onClick()</code> handler method. The Activity no longer needs to
126 of <code>setResult()</code>:</p>
135 <p>The whole <code>onCreate()</code> method should now look like this:</p>
170 <p>Define the <code>populateFields()</code> method.</p>
182 <p>This method uses the <code>NotesDbAdapter.fetchNote()</code> method to find the right note to
183 edit, then it calls <code>startManagingCursor()</code> from the <code>Activity</code> class, which
216 <p>Still in the <code>NoteEdit</code> class, we now override the methods
217 <code>onSaveInstanceState()</code>, <code>onPause()</code> and
218 <code>onResume()</code>. These are our life-cycle methods
219 (along with <code>onCreate()</code> which we already have).</p>
221 <p><code>onSaveInstanceState()</code> is called by Android if the
225 the counterpart to the <code>onCreate()</code> method, and in fact the
226 <code>savedInstanceState</code> Bundle passed in to <code>onCreate()</code> is the same
227 Bundle that you construct as <code>outState</code> in the
228 <code>onSaveInstanceState()</code> method.</p>
230 <p><code>onPause()</code> and <code>onResume()</code> are also
231 complimentary methods. <code>onPause()</code> is always called when the
232 Activity ends, even if we instigated that (with a <code>finish()</code> call for example).
235 <code>onPause()</code> as well, to take up less resources when in the
236 passive state. <code>onResume()</code> will call our <code>populateFields()</code> method
239 <p>So, add some space after the <code>populateFields()</code> method
242 <li><code>
243 onSaveInstanceState()</code>:
251 <p>We'll define <code>saveState()</code> next.</p>
253 <li><code>
254 onPause()</code>:
262 <li><code>
263 onResume()</code>:
272 <p>Note that <code>saveState()</code> must be called in both <code>onSaveInstanceState()</code>
273 and <code>onPause()</code> to ensure that the data is saved. This is because there is no
274 guarantee that <code>onSaveInstanceState()</code> will be called and because when it <em>is</em>
275 called, it is called before <code>onPause()</code>.</p>
280 <p>Define the <code>saveState()</code> method to put the data out to the
296 <p>Note that we capture the return value from <code>createNote()</code> and if a valid row ID is
297 returned, we store it in the <code>mRowId</code> field so that we can update the note in future
304 <p>Now pull out the previous handling code from the
305 <code>onActivityResult()</code> method in the <code>Notepadv3</code>
308 <code>NoteEdit</code> life cycle, so all the <code>onActivityResult()</code>
324 <code>onListItemClick()</code> method (again they are no longer needed,
325 only the <code>mRowId</code> is):</p>
347 a local variable in the <code>fillData()</code> method:
350 <p>Note that the <code>m</code> in <code>mNotesCursor</code> denotes a member field, so when we
351 make <code>notesCursor</code> a local variable, we drop the <code>m</code>. Remember to rename the
352 other occurrences of <code>mNotesCursor</code> in your <code>fillData()</code> method.
360 <p>You can see the solution to this exercise in <code>Notepadv3Solution</code>