The inconsistency you talk about only happens when authors poorly create their applications. Android's entire multitasking functionality is built on top of a stack of activities, which is easiest to think of as a stack of screen views. I start at my "desktop", click on my Photo Gallery, decide to share an image using Dropbox, and it takes me to choosing a Dropbox folder. That's roughly three activities or so (depending on how many screens within each app I have to go through) all on a stack. Built properly, if I decide I don't want to share on Dropbox while choosing a folder, I would just hit the back button, it'd pop the Dropbox folder browsing screen off the stack, and take me back to browsing my Photo Gallery. Poorly-created apps will try and "recreate" their internal activity stack when they're not supposed to. Let's say that getting to Dropbox's folder browser if I were to launch the app independently took four activities in and of itself. If Dropbox was poorly written, it would try and recreate that natural flow of previous activities when you're just trying to do a share, so hitting the back button won't take you to the Photo Gallery from sharing.
Sorry, it's complicated to explain but makes perfect sense when you're actually using a device. The tl;dr is that if app developers don't suck the back button's behavior is seamless and consistent.