Energy detection (ED) is a popular spectrum sensing technique for cognitive radios. The study of ED which takes into account the dynamic of traffic patterns of primary users, in the form of random signal arrival and departure, is of both theoretical and practical importance. Some of the existing works, however, resort to certain approximation techniques to characterize the detection performance. In this paper, given a pair of arrival and departure time instants, we first derive an exact expression for the conditional detection probability. The exact mean detection probability is then obtained via an average operation over the random arrival and departure times. To improve the robustness of the detection performance against random signal arrival and departure, we further propose a Bayesian-based ED scheme. We present simulation results to validate our analytic study, and show the performance gain of our proposed Bayesian approach.