Song's blog
Android
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?
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?
RxJava and Kotlin are new technic in 2015 - 2016. And I found out a memory
leak when I tried to use them.
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.
One of the third-party library which reference one Activity caused a
memory leak in my project. How to fix it?
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.
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.
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.
I've tried several approaches to optimize the code: Method count, Enum,
Serializable, Inheritance Hell, MVP, Test
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?
1). static reference to a Context
2). Client session out
1). UI rendering
2). Abuse of onResume
3). Speed up the build
A typical scenario when using HTTP request queue. How to handle the
important, latest or canceled request?
Firebase reported an ANR in the splash activity, which blocked many users to get into our app. I was investigating and trying to fix it.
It's easy to get to know how to cache response in OkHttp. But when you do it, it actually has more pitfalls than we thought.
Upgrading targetSDK to 33 is not a very hard job. At the same time, upgrading targetSDK just brought a bunch of issues that are about code.
Different Android OS version has different location and notification permissions. This is a blog to clarify thess for you.
Android UI
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.
This is the part two of canvas introduction. Canvas API on Android is a
helpful tool in some specific occasions.
ActionSheet on iOS is used to display a set of menus from the bottom. It's
like Android's dialog, just from the bottom.
These two methods are confusing concepts for lots of new developers. Hope
this post will help you.
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.
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.
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.
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.
RecyclerView's smootScrollToPosition() method is okay in some case, but far from perfect. In many cases, we have to use LienarSmoothScroller to help us to get the smooth scroll result as we expected. Here is a bunch of use case of using LinearSmootScroller
Changing the shape, such as transforming from rectangle to circle, is a typical effect we've seen in real life. And it would be even better to have some animation to have a smoother user experience. This article is to introduce how to do so.
The two most useful image tools, which one to use?
To make a perfect shadow on Android, we have to make extra effort than our coworker in iOS or Html. Android does have a very complex and unique shadow system to make our life even harder.
Android Architecture
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.
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.
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.
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.
MVVM is another pattern which is good for test and separation. Normally
you could use RxJava, or data-binding to implement a MVVM pattern.
MVP is a good pattern to help you design better. However, there are still
some questions about MVP, especialy for the junior developers.
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.
Lifecycle library is a good library. However, I get to know some tricky
issues about it, and here I want to share them.
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.
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.
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.
Android just released one new Library : WorkManager in this year's Google
I/O. Let's have a look.
What is the best code? This post is about my experience and my thoughts. Welcome to discuss with me.
What is the disadvantage of Fragment? Should we use Fragment in our project? I've been using it for many years, hope
my experience could help you.
I've watched one video to introduce Airbnb's architecture. Although it's a React video, but bad architecture exist
no matter which platform you're using. Let me explain why it is bad and how to make it better.
Here is several tips about ROOM when we try to use relation, pre-packaged database, text search and unit tests.
This post is not only to tell you how to use androidx.Activity, but also try to get the bottom of its design. This
kind of design is actually very common in the real world.
When you have multiple Activity which all reuse some part of logic, the impulse of using inheritance is temping. However you must have seen "BaseActivity -> NetworkActivity -> OrderActivity -> PlaceOrderActivity" such horrible activity hierarchy and know the trouble of this deep coupling. How could we avoid it?
Open Source Library
AutoGo is a libray to help you navigate to another Activity elegantly.
This is another lecture about making an annotation library.
Comparing to EventBus2, EventBus3 is using runtime annotation, which
definitely slows down the speed. How come EventBus has a better
performance than EventBus2?
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
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.
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.
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.
Some tips about Android Security
I just talked about Https in the last post. Here is one attack on Https
you may encounter in your development.
Android Test
Android project is hard to test. But it is not an excuse not to test it.
Let's explore the test world for Android.
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.
serious 2/2
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.
Test sometimes is hard. Test a Singleton is especially hard. How do we
conquer it?
series 2/2
We actually could test Kotlin project in Java. This is merely the
conversion between Kotlin and Java.
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.
Of course, we can write Kotlin code to test your code. Yes, JUnit is still
working. So don't worry about it.
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.
ROOM is another Android Architecture Component library. And you should
write unit test to make sure the database manipulation is workign as you
expect.
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
What is lambda? And what is the implementation of lambda in the level of
byte code?
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.
Generics is a feature that is easy to start, but hard to master. The most difficult part is the wildcard part. This
post is mostly about the confusing generics wildcards.
Kotlin
Kotlin, a new language invented by JetBrains. You may find it is even sweetier than you think.
kotlin sample
the sweetness of kotlin
NDK is a powerful tool when developing one Android app. So how kotlin cooperate with NDK?
proguard examples
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.
kotlin tips 1/N
DSL is a straighforward description about one specific domain, and Kotlin is powerful enough to make a DSL. We would
make a state machine DSL in Kotlin in this post, and show you how to make your own DSL in your app.
RxJava & RxJava In Android
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.
introduction of throttle, debouce, combineLatest. p.s. If you are a redux-saga user, you may find it familiar as
well.
React, React Native
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.
This post shows some examples about writing HoC, render props, to help you overcome some TypeScript erros you might
have.
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.
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.
React-Native-SVG is clearly a important part for React Native. It enable us to draw some shapes as we wish, and also
it provides some powerful feature, such as ClipPath, Path Animation, and so on.
Agile Development
Meeting is useful for communication. But we've all benn in a lot of long, tedious meeting. How do we host an
effective meeting?
test, a tool to make your life easier.
I list some books that is helpful to me. Hope it helps you too.
I've read multiple books in 2019, which includes React, React Native, Test, Management... Some of them are great
books which I do recommend.
iOS
I am new developer for iOS when I tried to work on iOS in our React Native project. However, my learning experience
might help many android develops who are interested in iOS and Objective-C.
Flutter
Flutter Layout Cheetsheet, a quick guidance when you need to find out which layout to use.
Flutter and React Native, which one is better?
Retrofit is a very useful library in Android. Now we will make one for the Dart.
Declarative-UI
RxDart
Languages
Development
Tools