Song's blog

Android

2016.01.20 Fixing An ANR
Drew shapes in one custom view, and found there are 68 thousand "Point" objects in the memory after a while, and got an ANR for that. How to troubleshoot and fix it?
2016.01.27 Animation: Over 16ms Per Frame?
3D ball is a custom view which rotate and show tags in 3-dimensions. However, most frames are over 16ms, which is bad for performance. How to fix it?
2016.02.01 Memory Leak in the RxJava project
RxJava and Kotlin are new technic in 2015 - 2016. And I found out a memory leak when I tried to use them.
2016.02.14 Activity Launch Mode With Examples
Activity Launch Mode can be confusing. It is pretty hard to understand if you don't know how to apply them to the real-life project. This post shows the examples and help you understand the four launch modes.
2016.05.14 Fix a memory leak
One of the third-party library which reference one Activity caused a memory leak in my project. How to fix it?
2016.07.09 How to Leak Memory on Android (1)
This series lists all the possible way to leak memory, which you should avoid to do in your project. This post is about registering a resource.
2016.07.10 How to Leak Memory on Android (2)
This series lists all the possible way to leak memory, which you should avoid to do in your project. This post is about anything that last longer than your activity, like static variable.
2016.11.22 Another example : fix a bug using Activity's launch mode
Using launch mode without cautiousness result in bugs. I had such one in my project. It's an Activity with multiple Fragment, and it use CLEAR_TOP improperly.
2017.01.15 Optimize my project
I've tried several approaches to optimize the code: Method count, Enum, Serializable, Inheritance Hell, MVP, Test
2017.02.10 How to create a floating window when your app is in the foreground?
This functionality includes two issues:
(1). create a floating window which is backward compatible;
(2). how to get to know if my app is displaying at a time?
2017.03.10 Fix two memory leaks
1). static reference to a Context
2). Client session out
2017.09.23 Some Examples of Improving Performances
1). UI rendering
2). Abuse of onResume
3). Speed up the build
2018.03.31 A scenario about one special request queue
A typical scenario when using HTTP request queue. How to handle the important, latest or canceled request?

Android UI

2016.01.17 How to draw a ScratchCard view?
I have been made a scratch card in app in 2014. It worked mostly okay. But I still have one issue. Two years later, 2016, I finally fixed this bug. This blog will show you how to draw different layer in a view, and the clear effect in the canvas.
2016.07.10 How to draw Takenaka's flag?
This is the part two of canvas introduction. Canvas API on Android is a helpful tool in some specific occasions.
2016.08.23 How to make an action sheet for Android?
ActionSheet on iOS is used to display a set of menus from the bottom. It's like Android's dialog, just from the bottom.
2017.04.10 getMeasuredHeight() vs getHeight()
These two methods are confusing concepts for lots of new developers. Hope this post will help you.
2017.08.15 Touch event process in one picture!
Touch Event system is complex and confusing, but it is also extremely important to draw any View with gestures. Xiaolin, a colleague of mine, summary all different occasion in one single picture. With this picture, it should be easy to find out what you need.
2017.12.24 Drag & Drop among groups
Drag and Drop in one View could be done by 1). Drag&Drop API on Android; 2). ViewDragHelper. But if you want to achieve drag&drop across two different group/list, it would be hard to do since we don't have such API.
2018.03.25 Making an expandable layout
This actually is a problem that I was asked when I was interviewed by one Company. I answer it quite correctly. After I came back, I wrote some code to implement it.
2018.08.29 Epoxy 101
Epoxy is a library about RecyclerView. However, its original sample is quite hard to grasp. Here I want to make this integration to Epoxy be easier for you.

Android Architecture

All five posts are Lunch & Learn I held in 2015, trying to overcome some architecture issues I had before

2015.11.16 Clean App (1) : MVC or not?
2015.11.17 Clean App (2) : Boilerplate in Android
2015.11.19 Clean App (3) : A Good Sample of MVC in Other UI framework(Griffon)
2015.11.21 Clean App (4) : Apply MVP to Android
2015.11.25 Clean App (5) : A reusable situation in MVP
2015.12.28 How kotlin make your architecture better in a fingerprint sample?
Use fingerprint in Java would not be an easy job. A lot of callbacks, different code in different palces(, like startActivityForResult() and onActivityResult()). However, Kotlin can be a saviour.
2016.09.22 Request the permission in Android6.0 easily
Just like fingerprint API, requesting permission dynamically on Android could be hard to write and read. I saw a couple of libraries try to solve this by using inheritance. However, I solve this problem by using composition.
2016.12.01 How writting test makes your architecture better?
Quite a lot of developer complaint about writing test. It's slow and seemingly useless. However, test could find the bug for you, especially after your refactor. Test could also make your architecture better.
2017.02.15 How to load image in a SDK project?
I've made a SDK which needs to load imagers from server. However the client of our SDK may have different ImageLoader library, such as UIL, Picasso, Glide or Fresco. How could we add an image loader library without adding more burdern to our client.
2017.03.08 Apply MVVM to your project
MVVM is another pattern which is good for test and separation. Normally you could use RxJava, or data-binding to implement a MVVM pattern.
2017.04.28 Typical questions about MVP pattern
MVP is a good pattern to help you design better. However, there are still some questions about MVP, especialy for the junior developers.
2017.08.04 How to hijack the lifecycle of Activity?
When you need to design a global lifecycle system, you may need to hijack the lifecycle of Activity. Here I offer three approach to achieve this.
2017.09.06 More than an introduction to the lifecycle library
Lifecycle library is a good library. However, I get to know some tricky issues about it, and here I want to share them.
2017.11.13 Something you need to know about the stable lifecycle library
If you were using the alpha or beta version of Lifecycle library, you definitely need to see this post when you switch to the stable version.
2017.11.19 More than the introduction of the ViewModel library
ViewModel is a new library for Android dev which helps your class survive configuration change. And also it is a good option if you are using MVVM pattern.
2017.12.01 Why do I disappoint at the ViewModel and LiveData frameworks?
After using LiveData and ViewModel for more than three months, I am not totally satisfied with these two libraries. I think there are some disadvantage that worth discussing in this post.
2018.05.12 Introduction to WorkManager
Android just released one new Library : WorkManager in this year's Google I/O. Let's have a look.
2018.11.11 What is the best code? This post is about my experience and my thoughts. Welcome to discuss with me.

Open Source Library

All three posts below are to teach you how you make your own ButterKnife, which also teaches you how to use annotation in your own project

2016.05.26 Make Our Own ButterKnife (1)
2016.05.27 Make Our Own ButterKnife (2)
2016.05.29 Make Our Own ButterKnife (3)
2016.08.11 How to make your own AutoGo?
AutoGo is a libray to help you navigate to another Activity elegantly. This is another lecture about making an annotation library.
2016.10.13 How EventBus3 becomes more efficient?
Comparing to EventBus2, EventBus3 is using runtime annotation, which definitely slows down the speed. How come EventBus has a better performance than EventBus2?
2018.07.20 How Hugo works, and how to improve it?
Hugo is a good library to help us debug. Digging into this library and we would learn a lot. However, we can still improve it by using Gradle's Transform API.

Android Security

2015.11.18 How to fail jd-gui?
This is a slight improvement if you don't want people to see the source code of your project. Of course, you still need proguard.
2015.12.25 Android's fingerprint
Android 6.0 has a new API about fingerprint. If you want to save something that can be accessed by your fingerprint, you may need the FingerPrint API and also the KeyStore API. This post just shows you how to do that.
2016.01.12 How does Https work?
This is a post about how Https works. It's totally theoretical, but it shows you in a picture that you would understand it very quickly.
2016.02.06 Security Tips in Android (1)
Some tips about Android Security
2016.09.13 Man in the middle attack
I just talked about Https in the last post. Here is one attack on Https you may encounter in your development.

Android Test

2016.01.01 How to test an Android project?
Android project is hard to test. But it is not an excuse not to test it. Let's explore the test world for Android.
2016.04.02 How to build a clean test project (1)?
A clean code base must to be a project that is friendly to test. Let's see how to build a clean project friendly to test.
2016.04.12 How to build a clean test project (2)?
serious 2/2
2016.05.30 How the Google MVP project tests?
Google has a TODO-MVP sample project, which is good presentation of how to architectu better. This article tries to analyze how it test its code.
2016.09.29 How to test a singleton in an Android Service? (1/2)
Test sometimes is hard. Test a Singleton is especially hard. How do we conquer it?
2016.10.03 How to test a singleton in an Android Service? (2/2)
series 2/2
2016.12.20 How to test a kotlin project in Java?
We actually could test Kotlin project in Java. This is merely the conversion between Kotlin and Java.
2017.03.15 Espresso Test Recorder
Introduction to another expresso tool: Espresso Test Recorder. It's still in its beta. But you could take a look. It helps you do your tests automatically.
2017.07.19 Write Test in Kotlin
Of course, we can write Kotlin code to test your code. Yes, JUnit is still working. So don't worry about it.
2017.08.12 How to inject Presenter to your Activity?
If you want to unit test your Activity, one huge challenge you may have is how to inject your mocked Presenter object in your test cases. The difficulty is the Presenter instance is initialized in the Activity#onCreate(), and it's hard to inject your mocked instance.
2018.04.12 How to unit test ROOM?
ROOM is another Android Architecture Component library. And you should write unit test to make sure the database manipulation is workign as you expect.
2018.09.05 Espresso: familiar tool, new journey
Espresso is great for your intergration test. But there are some pitfalls you may get as well. This article tries to help you to avoid these pitfalls.

Java

2016.03.18 Java8 Lambda
What is lambda? And what is the implementation of lambda in the level of byte code?
2016.05.01 A Problem about Java Access Modifier
Java Access Modifier seems easy and basic, but sometimes you may get confused. Here is an example of how I work around it to make my dev life better.

Kotlin

2015.11.28 Welcome to the Kotlin world
Kotlin, a new language invented by JetBrains. You may find it is even sweetier than you think.
2015.12.20 A simple sample of Kotlin in Android
kotlin sample
2015.12.23 Sweet Kotlin : Syntax Sugar (1)
the sweetness of kotlin
2015.12.24 How kotlin use NDK
NDK is a powerful tool when developing one Android app. So how kotlin cooperate with NDK?
2015.11.17 A sample of proguard (Gson, Retrofit, Kotlin)
proguard examples
2017.06.24 How Kotlin Implements Extension Functions?
kotlin can implement extensions, even to system classes, just like Ruby. So, how kotlin does it? What's the secret under the hoold. Let's take a look.
2018.08.12 Kotlin Tips Series 01
kotlin tips 1/N

RxJava & RxJava In Android

2015.12.10 RxJava + EditText
You could input multiple characters in EditText. And we may have some unique verfication about the input. RxJava is a powerful tool that may help us.
2015.12.13 throttleFirst() vs. debounce() ; combineLatest() vs. zip()
introduction of throttle, debouce, combineLatest. p.s. If you are a redux-saga user, you may find it familiar as well.

React, React Native

2019.01.01 How to Become a React Native Developer in 2019
This post is mostly from my own experience, and is good for anyone who want to learn React Native, especially for the native mobile developers. Hope this post can help you get into the world of React Native smoother.
2019.04.20 Pitfalls you might have when writing React (Native) with TypeScript
This post shows some examples about writing HoC, render props, to help you overcome some TypeScript erros you might have.
2019.04.30 Why saga is invented? And how saga handle async actions?
This post is not a API reference of saga, but a post to introduce why we need saga, and how saga works under hood. This is perfect for someone who have used saga, but don't understand saga well.
2019.07.02 Advanced TypeScript Tips
With types, TypeScript make the react/react-native development much safer. But TypeScript is not that easy to write, and you may have this or that kind of issue once a while. This post gives you some tips that make your TypeScript development smooth.

Agile Development

2016.01.08 How to have a healthy, meaningful meeting?
Meeting is useful for communication. But we've all benn in a lot of long, tedious meeting. How do we host an effective meeting?
2016.03.01 Do we need to test our Android codes?
test, a tool to make your life easier.
2016.07.23 Recommend some books about developers
I list some books that is helpful to me. Hope it helps you too.

2017.09.14 How to have an efficient stand-up meeting?
2018.03.14 Making a good on-boarding guide
2019.01.10 How to recruit the right people?

Tools

2015.12.12 [Tool] Translate json to java POJO classes
2015.12.14 [Tool] Generate Activity class from layout xml file automatically
2016.01.23 Writing a tool to get english script
2016.08.28 [Tool] Introduction to The Activity Template in Android Studio
2016.10.13 Android Studio does not recognize my cellphone?
2018.04.23 Using Node.js to deploy a fake server to speed up your development
Me: Songzhw, Toronto, Canada
My Email: songzhw2012@gmail.com