On Apr 7, 10:22 pm, Rui Martins <[EMAIL PROTECTED]> wrote:
> Now if, you look at the View object, it's the only one to have user
> input handlers, like:
> onMotionEvent( MotionEvent event ) ( or onTouchEvent for M5), and
> onKeyDown( int keyCode, KeyEvent event ) !
> An Activity doesn't have those !
>
> So, how can we handle user input, and react accordingly ?
You can override Activity.dispatchKeyEvent(), dispatchTouchEvent(),
and dispatchTrackballEvent(). This is the same model as in the view
hierarchy, where these exact same methods allow a parent view to
monitor events as they flow through it to its children. In effect,
the Activity is the top-level parent of the entire view hierarchy (in
fact internally there is a view in the view hierarchy called DecorView
that represents the activity).
Another way to look at this is that the OnXXX interfaces are there for
views that are receiving events being delivered to that view. The
activity does not have events sent directly to it, but rather events
flow through it on their way to the child views.
> If we call intent.startActivity() from within a View , we get an
> "Application Error", with the following description:
>
> "An error has occurred in process XXX
> calling startActivity() from outside of an Activity context requires
> the NEW_TASK_LAUNCH flag.
> is this really what you want ?"
You are doing something strange. The Context you have provided to
your view hierarchy is not your Activity, so you are trying to start
an activity from a different environment. Instead of deciding whether
or not you want to set that flag, you need to figure what context you
used to create the views in and change to using the Activity.
> The explanation, stating that a flag is required is fine !
> But how am I to know the answer to the question ? ("is this really
> what you want ?")
>
> http://code.google.com/android/reference/android/content/Intent.html#...
>
> If I force the Flag, I will enter into further configuration problems
> or limitations, due to how we MUST setup the Activity launchMode
> (http://code.google.com/android/reference/android/
> R.attr.html#launchMode)
Yep.
> Which means, that I will have several simultaneous tasks for every
> menu option, which is not what was wanted. I can possibly set my
> lauchMode to "singleTask", but "is this really what I want ?"
No, you don't want this, you want to call startActivity() on the
original activity context so the new activity will be started in its
context.
> I'm just trying to do a simple common thing, react to user input by
> launching a specific "sub" activity of the application, like in a menu
> kind of way.
>
> I know that there is the concept of subActivity in M5, that probably
> helps (not sure though), but this should be easy to do, even in M3 and
> apparently it's not !
No, all startSubActivity() does is start an activity that will deliver
a result back to the caller. The semantics are all the same...
except you -can't- use things like NEW_TASK_LAUNCH because the
original activity needs to wait for the new activity to finish before
it resumes interacting with the user.
> Either I'm missing something, or I haven't still got it, how this is
> supposed to work.
> And having Documentation only for M5 stuff, doesn't help much either.
Sorry about the documentation, but we had been early enough in the
development cycle that the releases represent snapshots of the current
system rather than things that would be maintained for a long period.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---