[android-developers] Re: How to close all activities in Activity stack and start a new one

2010-10-13 Thread nakvic
What just came in my mind, if it would suite your requirements: Start
activities with startActivityForResult. When an activity started,
register for broadcast and send the broadcast from your timer service.
The last started activity recieves broadcast and calls its finish with
result code, which you passes back to previous activity in stack. Once
activity receives the code it also calls  its finish passing result
code to its previous etc. The last activity (A) starts your (E).

It might be better to put the logic in one place, either in activity
class, the other will inherit, or in deligate class, if you use
different kind of activities (list, map etc) and cannot inherit single
one.

Oh, yeah, and dont forget to unregister broadcast once an activity is
paused.

I guess, you cannot use this approach, if top activity in the stack is
pause, therefore, you might try to use preferences to put a flag
close there. When activity is resumed it can check the flag and call
its finish with result code to inform parent activities to close.

It would be interested if anyone knows other way.

Regards,
nakvic


On Oct 9, 11:11 am, Jiang webs...@yahoo.cn wrote:
 When some activities is created, such as A-B-C-D, and in a timer, I need 
 to close all activities in Ativity stack in the order D-C-B-A (the timer 
 don't know what activities have been created), and then start a new Activity 
 E.

 How to implement this feature?

 Thanks.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: How to close all activities in Activity stack and start a new one

2010-10-10 Thread Indicator Veritatis
The Nope, sorry response from Dianne was her overly terse way of
saying that you cannot implement this feature, since it is not
supported -- nor is it likely to ever be supported. Why? Because it is
not according to the design of the Activity lifecycle.

Indeed: 9 times out of 10, when a developer asks a question like
yours, a little further probing reveals that the developer does not
really need to do such a thing after all. The illusion that you do
need to do it will evaporate upon close study of
http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle.
My suspicion is that all you really need to do is call finish() on
each Activity, popping them off the stack in the natural order (that
is why it is a stack, after all). Then start E.

Actually, I think Dianne would say not 9 times of 10, but 10-x
times out of 10, where x is some very small number, like the
probability of being hit by lightning on a clear day during the dry
season while standing on the floor of the Grand Canyon on one foot
while whistling Dixie;)

On Oct 9, 2:11 am, Jiang webs...@yahoo.cn wrote:
 When some activities is created, such as A-B-C-D, and in a timer, I need 
 to close all activities in Ativity stack in the order D-C-B-A (the timer 
 don't know what activities have been created), and then start a new Activity 
 E.

 How to implement this feature?

 Thanks.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en