Multiple instances of the same activity are created
In my previous post on auto receiving SMS, there’s a problem you can find easily that everytime a new message arrived, a new instance of MainActivity is created (which is a new task launched). It’s kind of wasting memory resources, right?
Here the solution:
1. Add attribute “android:launchMode” for MainActivity in AndroidManifest.xml, I use “singleTask”
2. Add an additiona activity launching flag: FLAG_ACTIVITY_SINGLE_TOP, in order to make it always on top of the screen.
Hope you learn something!