Mobile devices have proven to be transformative tools that help users perform a variety of everyday tasks. However, they also have tremendous potential to disrupt productive and desired time allocation, facilitating time-squandering through self interruptions of workflow and undesired task switching through distracting apps. Existing research has identified a variety of context variables which help predict the next app selected, but seldom give treatment to the pattern of app usage durations essential to understanding time allocation. Here we take a psychological computing approach to identify the key environmental factors that increase risk of early termination through unwanted switching. Using a task foraging model for time allocation, we construct an integrated measure of the background factors increasing switching temptation, and show that these can be converted into a computable measure of decision context that strongly impacts app duration. The foraging model gives new insight into the structural factors that promote task persistence and predict switch temptations, and suggests new ways to design productive environments.