Is it possible to find the current foreground activity in android.I am not using ActivityGroup.
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.
My guess is that it you need to look at the ActivityManager class. I took a brief look at the docs and this is what I came up with.
There’s a function:
From the Android docs:
Return a list of the tasks that are currently running, with the most recent being first and older ones after in order. Note that “running” does not mean any of the task’s code is currently loaded or activity — the task may have been frozen by the system, so that it can be restarted in its previous state when next brought to the foreground.
My thought would be if you pass in
maxNum=1, it should give you the most recent task that was run, ie. the top task. EachActivityManager.RunningTaskInfohas a property calledtopActivity.From the Android docs: The activity component at the top of the history stack of the task. This is what the user is currently doing.