Main activity  code from sample app