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

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.

主站蜘蛛池模板: 光泽县| 伊金霍洛旗| 乌兰县| 慈利县| 汉沽区| 马鞍山市| 南城县| 瓦房店市| 五寨县| 锦州市| 思茅市| 永善县| 汶上县| 临沭县| 临泉县| 南涧| 大安市| 延吉市| 昌图县| 迭部县| 双峰县| 安仁县| 黔江区| 西平县| 临邑县| 苏尼特右旗| 平度市| 诸暨市| 安多县| 梓潼县| 临邑县| 平利县| 射洪县| 县级市| 鄂托克旗| 曲阳县| 潞西市| 新干县| 湘潭市| 邵阳县| 方山县|