Building Android Apps 30条建议

简介: Building Android Apps — 30 things that experience made me learn the hard way There are two kinds of people — those who learn the hard way and those who learn by taking someone’s advice.

Building Android Apps — 30 things that experience made me learn the hard way

There are two kinds of people — those who learn the hard way and those who learn by taking someone’s advice. Here are some of the things I’ve learned along the way that I want to share with you:


  1. Think twice before adding any third party library, it’s a really seriouscommitment;
  2. If the user can’t see it, don’t draw it!;
  3. Don’t use a database unless you really need to;
  4. Hitting the 65k method count mark is gonna happen fast, I mean really fast! And multidexing can save you;
  5. RxJava is the best alternative to AsyncTasks and so much more;
  6. Retrofit is the best networking library there is;
  7. Shorten your code with Retrolambda;
  8. Combine RxJava with Retrofit and Retrolambda for maximum awesomeness!;
  9. I use EventBus and it’s great, but I don’t use it too much because the codebase would get really messy;
  10. Package by Feature, not layers;
  11. Move everything off the application thread;
  12. lint your views to help you optimize the layouts and layout hierarchies so you can identify redundant views that could perhaps be removed;
  13. If you’re using gradle, speed it up anyway you can;
  14. Do profile reports of your builds to see what is taking the build time;
  15. Use a well known architecture;
  16. Testing takes time but it’s faster and more robust than coding without tests once you’ve got the hang of it;
  17. Use dependency injection to make your app more modular and therefore easier to test;
  18. Listening to fragmented podcast will be great for you;
  19. Never use your personal email for your android market publisher account;
  20. Always use appropriate input types;
  21. Use analytics to find usage patterns and isolate bugs;
  22. Stay on top of new libraries (use dryrun to test them out faster);
  23. Your services should do what they need to do and die as quickly as possible;
  24. Use the Account Manager to suggest login usernames and email addresses;
  25. Use CI (Continuous Integration) to build and distribute your beta and production .apk’s;
  26. Don’t run your own CI server, maintaining the server is time consuming because of disk space/security issues/updating the server to protect from SSL attacks, etc. Use circleci, travis or shippable, they’re cheap and it’s one less thing to worry about;
  27. Automate your deployments to the playstore;
  28. If a library is massive and you are only using a small subset of its functions you should find an alternative smaller option (rely onproguard for instance);
  29. Don’t use more modules than you actually need. If that modules are not constantly modified, it’s important to have into consideration that the time needed to compile them from scratch (CI builds are a good example), or even to check if the previous individual module build is up-to-date, can be up to almost 4x greater than to simply load that dependency as a binary .jar/.aar.
  30. Start thinking about ditching PNGs for SVGs;
  31. Make library abstraction classes, it’ll be way easier to switch to a new library if you only need to switch in one place (e.g.AppLogger.d(“message”) can contain Log.d(TAG, message) and later realise that Timber.d(message) is a better option);
  32. Monitor connectivity and type of connection (more data updates while on wifi?);
  33. Monitor power source and battery (more data updates while charging?Suspend updates when battery is low?);
  34. A user interface is like a joke. If you have to explain it, it’s not that good;
  35. Tests are great for performance: Write slow (but correct) implementation then verify optimizations don’t break anything with tests.

If you have any questions drop me a tweet @cesarmcferreira!

 

form:https://medium.com/@cesarmcferreira/building-android-apps-30-things-that-experience-made-me-learn-the-hard-way-313680430bf9#.iz9oy4ekc

目录
相关文章
|
7月前
|
存储 Java API
Android 浅度解析:mk预置AAR、SO文件、APP包和签名
Android 浅度解析:mk预置AAR、SO文件、APP包和签名
855 0
|
5月前
|
XML 自然语言处理 Android开发
🌐Android国际化与本地化全攻略!让你的App走遍全球无障碍!🌍
【7月更文挑战第28天】在全球化背景下,实现Android应用的国际化与本地化至关重要 for 用户基础扩展。本文通过旅游指南App案例,介绍全攻略。步骤包括资源文件拆分与命名、适配布局与方向、处理日期时间及货币格式、考虑文化习俗及进行详尽测试。采用Android Studio支持,创建如`res/values-en/strings.xml`等多语言资源文件夹,使用灵活布局解决文本长度差异问题,并通过用户反馈迭代优化。最终,打造一款能无缝融入全球各地文化的App。
197 3
|
5月前
|
消息中间件 Android开发 开发者
🔍深度剖析Android内存泄漏,让你的App远离崩溃边缘,稳如老狗!🐶
【7月更文挑战第28天】在 Android 开发中,内存管理至关重要。内存泄漏可悄无声息地累积,最终导致应用崩溃或性能下滑。它通常由不正确地持有 Activity 或 Fragment 的引用引起。常见原因包括静态变量持有组件引用、非静态内部类误用、Handler 使用不当、资源未关闭及集合对象未清理。使用 Android Studio Profiler 和 LeakCanary 可检测泄漏,修复方法涉及使用弱引用、改用静态内部类、妥善管理 Handler 和及时释放资源。良好的内存管理是保证应用稳定性的基石。
85 4
|
5月前
|
XML 缓存 Android开发
🎯解锁Android性能优化秘籍!让你的App流畅如飞,用户爱不释手!🚀
【7月更文挑战第28天】在移动应用竞争中,性能是关键。掌握Android性能优化技巧对开发者至关重要。
45 2
|
6月前
|
ARouter IDE 开发工具
Android面试题之App的启动流程和启动速度优化
App启动流程概括: 当用户点击App图标,Launcher通过Binder IPC请求system_server启动Activity。system_server指示Zygote fork新进程,接着App进程向system_server申请启动Activity。经过Binder通信,Activity创建并回调生命周期方法。启动状态分为冷启动、温启动和热启动,其中冷启动耗时最长。优化技巧包括异步初始化、避免主线程I/O、类加载优化和简化布局。
83 3
Android面试题之App的启动流程和启动速度优化
|
5月前
|
Android开发
Android面试题经典之如何全局替换App的字体
在Android应用中替换字体有全局和局部方法。全局替换涉及在`Application`的`onCreate`中设置自定义字体,并创建新主题。局部替换则可在布局中通过`ResourcesCompat.getFont()`加载字体文件并应用于`TextView`。
80 2
|
6月前
|
缓存 JSON 网络协议
Android面试题:App性能优化之电量优化和网络优化
这篇文章讨论了Android应用的电量和网络优化。电量优化涉及Doze和Standby模式,其中应用可能需要通过用户白名单或电池广播来适应限制。Battery Historian和Android Studio的Energy Profile是电量分析工具。建议减少不必要的操作,延迟非关键任务,合并网络请求。网络优化包括HTTPDNS减少DNS解析延迟,Keep-Alive复用连接,HTTP/2实现多路复用,以及使用protobuf和gzip压缩数据。其他策略如使用WebP图像格式,按网络质量提供不同分辨率的图片,以及启用HTTP缓存也是有效手段。
91 9
|
6月前
|
XML 监控 安全
Android App性能优化之卡顿监控和卡顿优化
本文探讨了Android应用的卡顿优化,重点在于布局优化。建议包括将耗时操作移到后台、使用ViewPager2实现懒加载、减少布局嵌套并利用merge标签、使用ViewStub减少资源消耗,以及通过Layout Inspector和GPU过度绘制检测来优化。推荐使用AsyncLayoutInflater异步加载布局,但需注意线程安全和不支持特性。卡顿监控方面,提到了通过Looper、ChoreographerHelper、adb命令及第三方工具如systrace和BlockCanary。总结了Choreographer基于掉帧计算和BlockCanary基于Looper监控的原理。
95 3
|
6月前
|
安全 Android开发 数据安全/隐私保护
同样的 APP 为何在 Android 8 以后网络感觉变卡?
【6月更文挑战第8天】Android 8 及以后系统中,APP 网络感觉变卡源于更严格的安全机制和后台限制,系统对网络优化的侧重改变,以及APP自身兼容性问题。开发者需优化APP,适应新系统,用户可更新APP或检查权限设置。通过共同努力,有望改善网络卡顿现象,提升用户体验。
94 3
|
6月前
|
Java Android开发 Kotlin
Android面试题:App性能优化之Java和Kotlin常见的数据结构
Java数据结构摘要:ArrayList基于数组,适合查找和修改;LinkedList适合插入删除;HashMap1.8后用数组+链表/红黑树,初始化时预估容量可避免扩容。SparseArray优化查找,ArrayMap减少冲突。 Kotlin优化摘要:Kotlin的List用`listOf/mutableListOf`,Map用`mapOf/mutableMapOf`,支持操作符重载和扩展函数。序列提供懒加载,解构用于遍历Map,扩展函数默认参数增强灵活性。
50 0
下一篇
无影云桌面