In my application I need to detect whether my application is going to background or is switching to another activity of the same application… I know that I have to use the onPause method… but how can I distinguish the two cases?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
UPDATE: getRunningTasks has been declared to not be guaranteed to be accurate.
Call in onStop. onStop gets called after onStart of whatever takes over the screen – if its an activity in the same apk package then you’re not going into the background. This does require the GET_TASKS permission.
Or bind to a service onStart & unbind onStop – the service will then be onDestroyed when all your activities are stopped (or track binds vs unbinds if you don’t want to rely on onDestroyed getting called – because it might not..).