2015年3月22日 星期日

Java in Android development

Recently a friend on my facebook found that a famous App for scheduling meet-up and events  got some funny issues. So I've done some reverse engineering to the apk and got below finding.

Here's the code snippet:
Code:

Say most of the Android problems that I saw were actually Java  or OOP problems .
This one violates the rule that you should always call super(..) or super.foo() when you override the constructor/method of the super class. And the super.xxxx call must be in the first line of your overridden constructor/method. Or it may sometimes cause hidden bugs in your code.

Let check if this time will it produce any bug.
in Android source code:

Luckily , Application class extends ContextWrapper , which is a wrapper/decorator class of the Context abstract class. And there isn't anything to do in the constructor or onCreate() calls. But if one day the the implementation of Android framework is changed , the App will lose the inheritance feature  from its parent.



Some people start learning programming from Android development. It's a good thing cause Android development is really fun. You see result and user interaction immediately. But developers (like me) should spent some time on Thinking in Java or the Java Programming Language book to have deeper understanding of how to build a robust application.


PS. I haven't seen any application using ContetWrapper yet.
Code:
One usage that I can think of is in the Service or Activity class, you may use context from other where else (instead of using your own Context) and change the implementation of startActivity or startService calls ...etc. But this is out of my imagination. Please do share with me the usage if you have seen any example. Thanks !

沒有留言:

張貼留言