How can I avoid applications from sucking my battery and bypassing my lock-screen? I have now confirmed my suspicious... I will give you the example that just happened and motivated me to open this topic:

I was at my computer, with my phone in my desk. Suddenly new Viber messages arrive. With that, the phone vibrates and turns the screen ON. Worse than that, when I look at it I see that my lock-screen as been bypassed by Viber, which is now showing up on the screen the chat window where I received new messages.

Moreover, I left the phone untouched for 5 minutes, the screen stayed ON all that time...! This is unacceptable! So with this I detected two problems:


The lock-screen goes off with notifications. If I had the phone in my pocket I would be accidentally calling Barack Obama by now.
The screen stays ON forever. Which is not a problem, in 100 years from now. But in the 21st century, having the smartphone screen ON for hours is a huge issue!


My Android is 4.4.2 and my phone is a GT-I9301I (Samsung).

How can I stop apps from doing this?

Thanks!
The issue here appears to be Viber.  Reading the permissions on the app, it has the ability to:


disable your screen lock
prevent device from sleeping
modify system settings
close other apps
draw over other apps


First step, remove Viber.

If you absolutely must continue using Viber, check the app to see if any of these options are able to be turned off in the settings of the app.  If you can't find any settings that fix your issues, there are some more complicated options.

BEWARE THAT THINGS BEYOND THIS POINT CAN BREAK APP FUNCTIONALITY AND POSSIBLY BRICK YOUR DEVICE!

Something like an AppOpps launcher should let you get into the app permissions menu. Some of these things may be adjustable via the AppOpps menu, but that menu wasn't intended to be exposed and I believe has been disabled on newer Android releases.

Alternatively, if you're willing to void your (possibly already expired given the age of your device) warranty, risk bricking your phone, and don't mind wiping your data, you can try installing a custom ROM such as CyanogenMod that lets you control permissions more granularly, similar to AppOpps, but built into the operating system.