Android Doc routine-Notepad tutorial learning points!

Source: Internet
Author: User

Exersise 1:

 

Associate multiple fields with one row.

In the future, remember that the mapping between the from columns and to resources is done using the respective ordering of the two arrays. if we had more columns we wanted to bind, and more views to bind them in to, we wowould specify them in order, for example we might use {notesdbadapter. key_title, notesdbadapter. key_body} and {R. id. text1, R. id. text2} to bind two fields (field) into the row (and we wocould also need to define text2 in the notes_row.xml, for the body text ). this is how you can bind multiple fields into a single row (and get a custom row layout as well ).

 

Why do many functions require a context parameter:

The constructor for notesdbadapter takes a context, which allows it to communicate with aspects of the Android operating system. this is quite common for classes that need to touch the Android system in some way. the activity class implements the context class, so usually you will just pass this from your activity, when needing a context.

Like classification classes in Android, The simplecursoradapter needs a context in order to do its work, so we pass in this for the context (since subclasses of activity implement context ).

 

 

Exercise 2:

 

Sometimes we have to declare local variable so that we can use the variable in the Dalvik VM.

Note: We assign the mnotescursor field to a local variable at the start of the method. this is done as an optimization of the android code. accessing a local variable is much more efficient than accessing a field in the Dalvik Vm, so by doing this we make only one access to the field, and five accesses to the local variable, making the routine much more efficient. it is recommended that you use this optimization when possible.

 

Startactivityforresult () and onactivityresult () are often used for cross-process calls.

Onactivityresult () is the overridden method which will be called when an activity returns with a result. (Remember, an activity will only return a result if launched with startactivityforresult .)

The combination of startactivityforresult () and onactivityresult () can be thought of as an asynchronous RPC (Remote Procedure Call) and forms the recommended way for an activity to invoke another and share services.

 

 

Exercise 3:

 

Onsaveinstancestate (), onpause (), onresume () method

Onsaveinstancestate () is called by Android if the activity is being stopped and may be killed before it is resumed! This means it shoshould store any State necessary to re-Initialize to the same condition when the activity is restarted. it is the counterpart to the oncreate () method, and in fact the savedinstancestate bundle passed in to oncreate () is the same bundle that you construct as outstate in the onsaveinstancestate () method.

 

Onpause () and onresume () are also complimentary methods. onpause () is always called when the activity ends, even if we instigated that (with a finish () call for example ). we will use this to save the current note back to the database. good practice is to release any resources that can be released during an onpause () as well, to take up less resources when in the passive state. onresume () will call our populatefields () method to read the note out of the database again and populate the fields.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.