I am doing memory profiling with Android Studio and have noticed the memory occasionally (every one or two hours) has a huge spike:

Since this is random, it is impractical to stare at the screen to do a capture upon seeing the spike.
I wonder if there is a practical way to figure out the cause of this memory usage spike.
I am looking into this because the app crashes once in a while (apparently not every memory usage spike causes the crash). I suspect this spike is a possible culprit.
Heap dump is a snapthost for a certain point in time. It doesn't reveals the history.
For your question, one option is to make your app mointor and dump the heap itself.
Your screenshot shows the spike mainly comes from the "Others" category, and this is how Android Memory Profiler parses the output of "dumpsys meminfo --local --checkin %d" and then categorizes the usage into various categories. You can try to see if you app can collect similar data.
When the app detects a spike, it can dump the heap by calling API [Debug.dumpHprofData](https://developer.android.com/reference/android/os/Debug#dumpHprofData(java.lang.String).