It is never a good idea to hike by yourself in bear country. Not saying he deserved being attacked by a bear. Nobody does.
At the very least, always be sure to hike with someone that is a slower runner than you.