The primary goal of the proposed trial is to examine the effect of combining frequent self-monitoring via Ecological Momentary Assessment (EMAs) and automated interventions via Ecological Momentary Interventions (EMIs) provided by smartphone, on days of abstinence from drugs and alcohol and HIV risk behaviors over 6 months following treatment discharge. We will recruit 400 participants at discharge (both planned or unplanned) from Illinois' largest treatment organization and randomly assign them in a 2 x 2 factorial design to receive EMA only, EMI only, combined EMA+EMI, or neither (control). Participants in the 3 EMA and EMI groups will receive a smartphone and training after discharge. To help them self-monitor, individuals in the EMA groups will be randomly signaled 6 times daily for 6 months and asked to record their recent substance use, HIV risk behaviors (e.g., needle use, unprotected sex) and exposure to internal and external protective and risk factors, then to rate the extent to which these factors support their recovery or make them want to use drugs or alcohol. Individuals in the EMI groups will have 24/7 access to a smartphone recovery support system. In the combined EMA+EMI group, participants will receive feedback directly following completion of each 2-3 minute EMA, and EMA responses will be used to encourage EMI utilization. The primary hypotheses are