How can I detect which application was started most recently?
I'm not sure if this will suit your needs, but you could just look at the Recent Applications item stack located at the bottom right end of your Dock (assuming your Dock is located at the bottom of your screen).

If you don't have this stack visible in your dock, follow these steps:


Open Terminal (usually located in Applications > Utilities)
Type (or copy and paste) the following:

defaults write com.apple.dock persistent-others -array-add '{"tile-data" = {"list-type" = 1;}; "tile-type" = "recents-tile";}'; killall Dock

Press the Return key
The Dock will quit and relaunch
You should now see a new item stack with recently used applications (at left of the Trash can)
Clicking on this will display your most recent apps
You can right-click (or control-click) on the icon to change what is displayed and how it is displayed. For example, choosing to display it as a List will show the most recent app at the top, and choosing the Grid option will display the most recent app at top left, and so on. 


Regardless, the advantage of this over the Apple > Recent Items option is that everything is listed in the order they were run/accessed, instead of being listed in alphabetical order.