The Android Notepad tutorial (exercise 3)
At the end of exercise 2 we found Notepadv2 crashes if the back button is pressed while the activity is in the foreground. Notepadv3 adds a full activity lifecycle to the NoteEdit class to solve this. This exercise is well documented in http://developer.android.com/resources/tutorials/notepad/notepad-ex3.html
Rather than importing the Notepadv3 code supplied as a new project, I started a new project based on the final code I had for Notepadv2. Outside of Eclipse I copied the Notepadv2 folder to create a Notepadv3 folder in the Eclipse workspace. Then in Eclipse I selected File -> New -> Android Project. I then selected ‘create project from existing source’, and filled in the project and activity names.
If you are following this, click on Finish. Right click on the new project in the package explorer window and select close unrelated projects.
Now we need to create a notepadv3 activity from the notepadv2 activity. Double click on the Notepadv2.java class in the package explorer window. Rename the package name com.android.demo.notepad3. You will see a red wavy line under the package name, indicating an error. If you hover the mouse over the package name Eclipse will suggest two quickfixes. Click on the first one – move notepadv2.java to package com.android.demo.notepad3.
The notepadv2 class will have lots of errors, but they are easy to fix. Double click on the notepadv2 class. Change the name of the activity to Notepadv3 on line 32. Then hover over the error and accept the quickfix ‘Rename compilation unit to Notepadv3.java’.
There are lots of remaining errors: the first one is ‘NotesDbAdapter cannot be resolved to a type’. We resolve these by moving the compilation units NoteEdit.java and NotesDbAdaptor.java from the com.android.demo.notepad2 package to the com.android.demo.notepad3 package. Simply drag and drop within the package explorer window. Then delete the old package.
Now lets update the android manifest. Double click on it and on the Manifest tab of the source window change the package name to com.android.demo.notepad3. On the XML tab change line 4 (the one with the error) to read
Note that the error indication will not disappear until you choose save from the File dropdown menu.The remaining error is about imports. As usual this is fixed by Control-Shift-O.
The 10 steps documented in the tutorial are clear so you should have no difficulty following them.
Rather than importing the Notepadv3 code supplied as a new project, I started a new project based on the final code I had for Notepadv2. Outside of Eclipse I copied the Notepadv2 folder to create a Notepadv3 folder in the Eclipse workspace. Then in Eclipse I selected File -> New -> Android Project. I then selected ‘create project from existing source’, and filled in the project and activity names.
If you are following this, click on Finish. Right click on the new project in the package explorer window and select close unrelated projects.
Now we need to create a notepadv3 activity from the notepadv2 activity. Double click on the Notepadv2.java class in the package explorer window. Rename the package name com.android.demo.notepad3. You will see a red wavy line under the package name, indicating an error. If you hover the mouse over the package name Eclipse will suggest two quickfixes. Click on the first one – move notepadv2.java to package com.android.demo.notepad3.
The notepadv2 class will have lots of errors, but they are easy to fix. Double click on the notepadv2 class. Change the name of the activity to Notepadv3 on line 32. Then hover over the error and accept the quickfix ‘Rename compilation unit to Notepadv3.java’.
There are lots of remaining errors: the first one is ‘NotesDbAdapter cannot be resolved to a type’. We resolve these by moving the compilation units NoteEdit.java and NotesDbAdaptor.java from the com.android.demo.notepad2 package to the com.android.demo.notepad3 package. Simply drag and drop within the package explorer window. Then delete the old package.
Now lets update the android manifest. Double click on it and on the Manifest tab of the source window change the package name to com.android.demo.notepad3. On the XML tab change line 4 (the one with the error) to read
... activity name=".Notepadv3" ...
Note that the error indication will not disappear until you choose save from the File dropdown menu.The remaining error is about imports. As usual this is fixed by Control-Shift-O.
The 10 steps documented in the tutorial are clear so you should have no difficulty following them.
Comments
Post a Comment