官术网_书友最值得收藏!

FAQ

  1. What is wrong with this method definition?
    doSomething(){
      // Do something here
    }

    No return type is declared. You do not have to return a value from a method, but its return type must be void in this case. This is how the method should look:

    void doSomething(){
      // Do something here
    }
  2. What is wrong with this method definition?
    float getBalance(){
      String customerName = "Linus Torvalds";
      float balance = 429.66f;
      return customerName;
    }

    The method returns a String (userName) variable, but the signature states that it must return a float. With a method name like getBalance, this code is probably what was intended:

    float getBalance(){
      String customerName = "Linus Torvalds";
      float balance = 429.66f;
      return balance;
    }
  3. When do we call the onCreate method? !Trick question alert!

    We don't. Android decides when to call onCreate as well as all the other methods that make up the lifecycle of an Activity. We just override the ones that are useful to us. We do, however, call super.onCreate so that our overridden version and the original version both get executed.

Note

For the sake of technical accuracy, it is possible to call the lifecycle methods from our code, but we will never need to do this in the context of this book. It is best to leave these things to Android.

主站蜘蛛池模板: 祁门县| 遂川县| 平果县| 吉安县| 通州市| 泰兴市| 玉环县| 临湘市| 韶关市| 双峰县| 东光县| 皋兰县| 府谷县| 邓州市| 南充市| 修武县| 板桥市| 六盘水市| 临清市| 乾安县| 雅安市| 铜鼓县| 达尔| 岱山县| 高尔夫| 新蔡县| 武山县| 来凤县| 图木舒克市| 澎湖县| 五大连池市| 隆德县| 图们市| 郧西县| 阆中市| 桂东县| 旅游| 乌拉特中旗| 招远市| 利津县| 京山县|