We will recruit a total of 400 participants in 4 cohorts of 100 people from sequential discharges (both planned or unplanned) over 2 months starting in months 7, 19, 31, 43 and follow them for 6 months post discharge. Using urn randomization, we will randomly assign participants at discharge in a 2 x 2 factorial design to receive EMAs only, EMIs only, combined EMA+EMI or control (no EMA or EMI). Post-randomization, participants assigned to the EMA, EMI and combined EMA/EMI groups will receive a smartphone for 6 months with 450 call minutes, 500 text messages and unlimited data plan monthly. Those in the EMA only and EMA/EMI combined group will be asked at 6 randomly selected times each day (183 days total) to record their past-30-minutes involvement in HIV risk behaviors and substance use, and their exposure to internal and external risk and protective factors and rate the extent to which these factors support their recovery, make them want to use drugs and/or alcohol. Those in the EMI only and EMA/EMI combined group will have continuous access to a suite of smartphone based support services (EMIs). To minimize interference with treatment, phones will be issued and trainings will be done after discharge. To minimize potential contamination across conditions, trainings for each condition will occur on separate days. During the month following treatment discharge & training, participants in the three experimental groups will return to the research office 2 times a week for research staff to check participant's proficiency operating the phone and collect urine screens. To control for the effects of attention, the control group will also return to the research office 2 times a week for urine screens and a short survey on non-phone related topics. Research office visits and trainings will be done by Protocol Monitors (not interviewers). Research Interviewers blind to condition will conduct the discharge, 3 and 6 months post discharge interviews and urine tests. EMA and EMI utilization data will be electronically recorded immediately via a mobile/web application and used to track implementation.