This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Problem : I want one "Dialogue Activity " to be always on the TOP of my Application . Let us say Activities as A1 ,A2 and so on... and Dialog Activity as D
Now Application starts and A1 is shown to the user. Now A1 launches (in onCreate() ) D activity on top of it. Since D activity is just a Dialog Activity showing some information to the user. It is on one side of the screen and is draggable so that user can move it to any part of the screen. At this time ,user can still can see A1 and touch it. So now user goes to Activity A2 from A1 ( By pressing a button in A1) .
Requirement : Now i want is that the D activity comes over A2 automatically. Now when user launches A3, D comes over A3 and so on so forth.....
So Activity Task movement is as follows
(Launch A2 from A1)
A1 A2 D
(Launch A3 from A2)
A1 A2 A3 D
Android doesn't really provide you the control over the Activity stack to do anything like this directly. If you are allowing a user to interact with a paused Activity while it is in that state underneath another Dialog themed Activity (a pattern that really isn't recommended), then you will have to implement logic in your application to finish the current "Dialog" and re-display it again after the new Activity has launched (persisting its state somewhere so it can show up looking the same as it did before you closed it). The "Dialog" can either finish itself when it detects that it has been paused (because your new A2 or A3 has come over the top of it) and that new Activity can be responsible for launching a new version of the "Dialog" in onCreate() ...OR... You might be able to use the finishActivity() method from the paused Activity to force finish the "Dialog" before launching the next Activity, which will then automatically re-display the "Dialog".
The above is all very hacky because it truly is using the Activity stack in a way that is was not designed to be used. Another approach you might consider is to implement this application with Fragments instead. Using Fragments, you can swap out (using the replace() method) the screen section underneath because you define the container view location where a Fragment hierarchy should load. The "Dialog" can also be a Fragment that just displays itself inside of a different container location.
You can use Intent flags to manage how a new Activity is launched; things like pulling an existing instance from within the stack rather than creating a completely new one, or modifying how the new instance is tracked in the stack history. However, there is no flag that allows you to insert a new Activity in between two existing Activity instances in the stack...the new Activity you launch will always be on the top of the stack. Allowing this behavior at the framework level has too many consequences that can break result delivery chains that may exist from one instance to another.