You can get your code back from local history of Android Studio. You need to follow below steps.
1) Launch Android Studio and open the file (It can be your activity or xml code file)
2) Click on VCS
3) Go to Local History from the menu
4) And select Show local history
5) No 5th step :)
Get your code from history