I'm glad you saw those flaws with my idea, I have finish()'ed
activities from separate threads before, this is not an issue so long
as you have a reference to the activity in the other thread.  And yes
you would need to keep track of every activity, which is why your
original proposal is not such a bad idea.

Consider this example:

//here we are launching a new activity

Intent i = new Intent(this, nextActivity.class);
startActivityForResult(i, START_SUBMIT);

//this activity will return a result code
//which is handled here in the class that started the new activity
//request is the int that called the new activity (START_SUBMIT)
//result is the code the activity returned when it finished
onActivityResult(int requestCode, int resultCode, Intent intent)

So if your application determines that the service is no longer
running it would set is result code to some int you have defined, say
INVALID_STATE and finishes itself.

Then the calling activity would call the onActivityResult with both
the code that was started (allowing you to know which activity you
came from) and the result code (in this case INVALID_STATE).  From
here this can continue until you reach the bottom of the stack and you
can start the first activity over.


On Dec 28, 12:35 pm, André Oriani <aori...@gmail.com> wrote:
> There is some difficulties with you proposal.
> -Service and UI are running on different process.
> -I will have to keep track of activities ( they will have to put
> themselves in some data structure) .
> - They are killed ( SIGKILL) , they won't have time to save anything
> neither to excute onDestroy.  The problem will happen when process are
> launched again ( so no memory abou what happened before, just the
> stack of activity because framework does the job)
>
> On Dec 28, 2:56 pm, theSmith <chris.smith...@gmail.com> wrote:
>
> > If you want to, you can override the onDestroy() method of the service
> > and have it call finish() on each of you activities in the stack.
> > This should result in the behavior you are looking for I believe,
> > because the system would be forced to create a new instance of your
> > application, thus starting a new service with it.
>
> > -theSmith
>
> > On Dec 28, 10:35 am, André Oriani <aori...@gmail.com> wrote:
>
> > > Hi all,
>
> > > Differently from most application, the state of my application is not
> > > controlled by its stack of activities but by the state of a background
> > > service.
>
> > > Here is my problem. Suppose I have a task running  with  a non empty
> > > stack of activities. The top activity is paused on background and not
> > > visible.  Then for some reason the  process that host both the service
> > > and top activity is killed.  When I somehow return to my app
> > > application ( by pressing back key, resumimg from recent apps menu),
> > > the framework launches  the application again with the activity that
> > > was on the top of the activity stack  before process got killed.
>
> > > Okay, you would say that it is the expected behavior. But because my
> > > service is no longer alive , the top activity is no longer valid ( as
> > > the other activities which remain  on stack) . I would like to clear
> > > the whole activity stack  and launch another activity to explain the
> > > current situation to user.
>
> > > I could put the follow code on every activity "if(not valid state)
> > > finish() and launch a new activity with clear top flag  enabled " but
> > > I don't think it is clever.  Is there a better way to control which
> > > activity will be launched after application is killed ?
>
> > > Tks,
> > > André

-- 
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

Reply via email to