Fix memory leak issue.

Activities now transition correctly, removing unneeded activities from the stack so they can be garbage collected.