I certainly don't have all of the answers, but keep reading and I'll share what I've learned about how to break a bad habit.
It's easy to get caught up in how you feel about your bad habits. You can make yourself feel guilty or spend your time dreaming about how you wish things were ... but these thoughts take you away from what's actually happening. Instead, it's awareness that will show you how to actually make change. When does your bad habit actually happen? How many times do you do it each day? Where are you? Who are you with? What triggers the behavior and causes it to start?
Simply tracking these issues will make you more aware of the behavior and give you dozens of ideas for stopping it.
Here's a simple way to start: just track how many times per day your bad habit happens. Put a piece of paper in your pocket and a pen. Each time your bad habit happens, mark it down on your paper. At the end of the day, count up all of the tally marks and calculate your total.
In the beginning your goal isn't to judge yourself or feel guilty about doing something unhealthy or unproductive. The only goal is to be aware of when it happens and how often it happens. Wrap your head around the problem by being aware of it. Then, you can start to implement the ideas in this article and break your bad habit.
Breaking bad habits takes time and effort, but mostly it takes perseverance. Most people who end up breaking their bad habits try and fail multiple times before they make it work. You might not have success right away, but that doesn't mean you can't have it at all.