2

Is there a way to detect which activity is visible at the moment?

I have an activity that is launched whenever the server sends an asynchronous message, but if the user hasn't answered the previous message I don't want to take over the screen to display the new message. So I need to know if there is an Activity running of a particular type before launching.

I know I could just store this is inside the application, but I was wondering if there was a native way of doing it.

EDIT: And I do need this... so if you don't know the answer don't say "You will never need this"

EDIT 2: The application is not for the market, and its for a company that will have it running in the Galaxy Tab by itself

Thanks

Totic
  • 1,281
  • 1
  • 10
  • 21

2 Answers2

3

You can't do that. I tell you more: you won't ever need it.

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
  • This answer is kind of direct ^^ but i think that's the truth. What code should ever needs to know that except of the running activity which automaticly knows that by the fact that it's running at the moment. – Chris Mar 09 '11 at 10:56
  • 1
    I do need to know, thats why I asked it... I hate when I get this sort answer. if You don't know then just say it, but don't assume people are asking just for the sake of it. – Totic Mar 09 '11 at 11:18
  • Because I have an activity that shouldn't launch if another one is running. – Totic Mar 09 '11 at 11:40
  • Please, update your question and try to be more descriptive. Then we will be able to help you. – Vladimir Ivanov Mar 09 '11 at 11:42
  • exactly the same problem like me – bofredo Aug 29 '13 at 12:28
  • Ant what about the case, when i have two class in my app, activity and broadcast reciever with google push notification and when i get the message. When i get the message from google can heppens two things: my activity was already removed from task by system (in this case i want put on front) or the activity is still in top and i dont want do nothnig. how i do this without i know is the activity is still working:) – m1uan Dec 13 '13 at 00:45
2

Meh. here it is. But what you are doing is just a hack.

This is more likely to be the fix for your use-case. Use the Application class to keep a track of your app's current state.

Community
  • 1
  • 1
Reno
  • 33,594
  • 11
  • 89
  • 102