The second sample code should work.
in the emulator hangs on "wait for debugger"
The problem seems related to the Emulator that cannot attach the debugger.
Try to follow these steps:
-Close the Emulator
-Go to AVD manager and recreate the emulator again
-Start the emulator and try to run the app
Alternatively try to run the app on a real device.