About NotePad Tutorial

本文详细介绍了Android布局文件的基本结构,包括必须的XML头信息、常用的LinearLayout定义及命名空间使用方法。此外,还深入解析了startActivity()与startActivityForResult()的区别,以及如何通过onActivityResult()方法接收返回结果。

    今天学习NotePad Tutorial。把自己认为重要的Copy过来。

   一,Here are some things you should know about a layout file:

      1,All Android layout files must start with the XML header line: <?xml version="1.0" encoding="utf-8"?>.

      2,The next definition will often (but not always) be a layout definition of some kind, in this case a LinearLayout.

      3,The XML namespace of Android should always be defined in the top level component or layout in the XML so thatandroid: tags can be used through the rest of the file:

  • xmlns:android="http://schemas.android.com/apk/res/android"

 二,关于startActivity()和startActivityForResult():

      The startActivityForResult() method fires the Intent in a way that causes a method in our Activity to be called when the new Activity is completed. The method in our Activity that receives the callback is calledonActivityResult() and we will implement it in a later step. The other way to call an Activity is usingstartActivity() but this is a "fire-and-forget" way of calling it — in this manner, our Activity is not informed when the Activity is completed, and there is no way to return result information from the called Activity withstartActivity().

  三,关于onActivityResult():

   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 withstartActivityForResult.) The parameters provided to the callback are:

      1,requestCode — the original request code specified in the Intent invocation                       (either ACTIVITY_CREATE or ACTIVITY_EDIT for us).

      2,resultCode — the result (or error code) of the call, this should be zero if everything was OK, but may have a non-zero code indicating that something failed. There are standard result codes available, and you can also create your own constants to indicate specific problems.

      3,intent — this is an Intent created by the Activity returning results. It can be used to return data in the Intent "extras."

转载于:https://my.oschina.net/u/127911/blog/17307

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值