Hi All,

I have been learning about the complex problem of Activities, launch
flags, Intent flags, tasks and the Activity stack. I've been trying to
solve what I thought would be a simple problem.

Our application has a Search Activity that can possible be entered
through two paths:

1) ServerListActivity > SearchActivity
2) URLLaunchActivity > SearchActivity

In both cases, the same SearchActivity should be reused because the
user may have gone beyond the search to other activities, and we want
to 'pop the stack' back to the SearchActivity if they are launching
from a URL.

The URLLaunchActivity is set up to handle VIEW intents, and it
basically forwards those intents on to the SearchActivity. I have
implemented special handling for the VIEW action in both onCreate of
SearchActivity as well as onNewIntent.

I have added android:launchMode="singleTask" to the SearchActivity
manifest entry, which makes sure that the same SearchActivity is
always used when handling the intents. This is the only flag I could
use to make this work even partially correctly. Any other flags were
not what I wanted at all, unless I have missed something fundemental
in my learning stages -- a probable thing, as this is complicated
stuff.

Because we are searching for patient data with this application, we
need to comply with HIPPA requirements and have a timeout associated
with the SearchActivity so that if the application is idle for long
enough, the SearchActivity will finish and display a dialog to the
user stating that there was a timeout.

This is where I seem to have trouble. Because a new Task is started
when the SearchActivity is launched, the usual startActivityForResult
method will not work because the intent is immediately cancelled due
to the new task being started. Okay, so I've had to come up with a
static flag on the SearchActivity to signal that the timeout had
occurred so the dialog can be displayed to the  user when returning to
either the ServerListActivity or the URLLaunchActivity. This isn't
terrible, but it is unexpected. The only clue to this behaviour was a
small LOG statement from the ActivityManager and the immediate
callback of the onActivityResult with a cancelled flag set.

The real problem is that I want to make sure that if the application
is launching a URL, URLLaunchActivity launches SearchActivity and I
want the application to exit back though that same stack always. What
I am seeing is the following strange behaviour:

App Launch -> ServerListActivity -> SearchActivity | <User long
presses HOME and switches to Browser>
User clicks on link in browser -> URLLaunchActivity ->
ServerListActivity | <Inactivity Timeout Occurs> | ServerListActivity

The timeout occurs, and the ServerListActivity is returned to, not the
URLLaunchActivity as desired. That surprises me greatly.

Some extra information that might help anyone interested enough to
still be awake at this point in my story:

- In URLLaunchActivity the intent flags FLAG_ACTIVITY_CLEAR_TOP and
FLAG_ACTIVITY_SINGLE_TOP are used when launching SearchActivity.
- I noticed that in ServerListActivity I am NOT setting either of
those flags. Perhaps this is leading to this bad behaviour?

I've read all of the documentation (that I know of) on the subject,
and thought I had a grasp of what's happening. But I'm still not sure.
Is there any advice on how I might simplify this scenario?

Thanks in advance for any insight.

-Neal

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