Predicting molecular activity and quantitative structure-activity relationship (QSAR) is important for drug discovery and optimization. With molecular structures as frames, graph neural networks (GNNs) are suited for activity prediction but tend to overlook activity-cliffs (ACs) where structurally-similar molecules have vastly different activity values. To address this, we introduced a new online triplet contrastive learning framework ACANet that incorporates a unique activity-cliff-awareness (ACA) loss function, enabling efficient AC-awareness during training. The ACA loss enhances metric learning in the latent space and task learning in the target space simultaneously to make networks aware of ACs. ACANet outperformed the state-of-the-art machine learning and deep learning models in activity prediction and AC awareness on 39 benchmark datasets. ACA loss function is superior in AC-awareness than the mean absolute error and mean squared error loss functions. This innovative approach opens new avenues and provides valuable tools for applications in drug discovery and chemical engineering.