Keeping activity and background tasks in sync