Getting started

I spent a whole day to go through the second example of android (Note book App). Basically, I can understand how to use Activity, Intent and SQLite in android platform already, but it's only a superficial level. For example : using multiple activities and transfering parameters among of them with Intent.

Below are some spots need to be advert:

  • startManagingCursor();

          It allows Android to take care of the Cursor lifecycle instead of us needing to worry about it

    private static final int INSERT_ID = Menu.FIRST;

    private static final int DELETE_ID = Menu.FIRST + 1;

   Be ware of that we need to increase the index number when we want to add new menu items

  • Optimization – How to use variables efficiently in android platform

   Finally, the new Activity has to be defined in the manifest file:

 

Before the new Activity can be seen by Android, it needs its own Activity entry in the AndroidManifest.xml file. This is to let the system know that it is there and can be called. We could also specify which IntentFilters the activity implements here, but we are going to skip this for now and just let Android know that the Activity is defined.There is a Manifest editor included in the Eclipse plugin that makes it much easier to edit the AndroidManifest file, and we will use this. If you prefer to edit the file directly or are not using the Eclipse plugin, see the box at the end for information on how to do this without using the new Manifest editor.

 

1.    Double click on the AndroidManifest.xml file in the package explorer to open it.
2.    Click the Application tab at the bottom of the Manifest editor.
3.    Click Add... in the Application Nodes section.
If you see a dialog with radiobuttons at the top, select the top radio button: "Create a new element at the top level, in Application".
4.    Make sure "(A) Activity" is selected in the selection pane of the dialog, and click OK.

  5.    Click on the new "Activity" node, in the Application Nodes section, then type .NoteEdit into the Name* field to the right. Press Return/Enter.

 

   The Android Manifest editor helps you add more complex entries into the AndroidManifest.xml file, have a look around at some of the other options available (but be careful not to select them otherwise they will be added to your Manifest). This editor should help you understand and alter the AndroidManifest.xml file as you move on to more advanced Android applications.

  •  Two different methods to transfer parameters among of activities
bundle
1bundle.putString(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString());
2bundle.putString(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString());
3if (mRowId != null{
4   bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
5}

6
7Intent mIntent = new Intent();
8mIntent.putExtras(bundle);

Intent

1Intent intent = new Intent();
2intent.putExtra(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString());
3intent.putExtra(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString());


 

 

posted on 2009-01-08 18:14  Edgar Sun  阅读(205)  评论(0编辑  收藏  举报

导航