How can i know current foreground activity(not from service)?

I am having alert generation application. I want to start or switch to other(Third) activity from current activity(foreground) using another activity's context(middle). From current activity(foreground) i m switching to other(middle) activity using intents and from this switched activity again i m switching to another(third) activity using intents. Due to such scenario, i am getting little but flash of middle activity in between current foreground activity and final most(third) activity.
How can i resolve this one?

For this purpose i want to know current foreground activity or is there any other solution?

I am not having any ideas about this one. Highly appreciate solutions.

There is a topActivity field defined on the RunningTaskInfo class. You can get a list of running tasks via the getRunningTasks(int) method in the ActivityManager. Traverse through that list to find the currently active task by checking the topActivity field.

There is a topActivity field defined on the RunningTaskInfo class. You can get a list of running tasks via the getRunningTasks(int) method in the ActivityManager. Traverse through that list to find the currently active task by checking the topActivity field.

Regards,

Johan

Thanks a lot Johan...
Can i hide the middle activity view while switching from foreground activity view to third activity view because i m using intents?
Due to use of intents for switching activities i get flashing of middle activity's view which i don't want.

Maybe I don't really understand what you are trying to achieve. Basically you shouldn't interfere with which activity is placed before what other. You should let the ActivityManager take care of that for you. There is an AlarmManager in Android, which you can utilize to activate something at a certain point in time. Maybe that's what you need?

Maybe I don't really understand what you are trying to achieve. Basically you shouldn't interfere with which activity is placed before what other. You should let the ActivityManager take care of that for you. There is an AlarmManager in Android, which you can utilize to activate something at a certain point in time. Maybe that's what you need?