开发者

Android Performance improvement

I have a doubt which will be better - using getter, setter methods or dire开发者_C百科ct field access ?

In android site Performance Tips - its given as "Avoid Internal Getters/Setters".

My choice is to use direct field access, but my friends are telling to use getter setter methods in Android. Is that right if so then what is the use of using getter setter methods? How the performance will be improved?


To add to the answer from Ed, what the link you send refers to is to avoid internal getter/setter. Within the same class, using the getter/setter to access a field will cost you for nothing...

Does not mean you should not use getter/setter from other classes. The cost you may pay in performance is worth it in maintainability and code design / structure.


The choice between using getters and setters and allowing for direct field access is not typically one of performance, but instead one of maintainability and encapsulation of data. Typically you will use getters and setters to have tighter control over your data.

Unless you are running in a tight loop that needs to go as fast as the hardware will allow it and the function call is actually proven to be cosnuming a relatively significant amount of CPU time you don't have to worry about the performance.


How to Improve app performance

Performance is most important for user fulfillment

Some technique to improve app performance

1) Avoid Unnecessary variables and package create only needed variables and import used package remove unused package

2) Create Setter getter to store and access data

3) Replace array to List or any java collection

4) Data reuse

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜