On Apr 8, 3:21 pm, Rui Martins <[EMAIL PROTECTED]> wrote: > I checked my code, and I was giving the Application to the View > Constructor, as the context, which I believe is correct, although we > can also pass the activity (this)
No, it is not correct to give the Application. The views you are making are running as part of your activity, so they should be created in the activity context. > My code was: > setContentView( new GameMenuView( getApplication() ) ); That's wrong. Just pass in "this", the activity. > > - Using NEW_TASK_LAUNCH like this is fundamentally broken (unless that > > is the semantics you really want)/ > That's why I was saying that I didn't get how this View => Activity > communication was supposed to work, since this flag (Hack) solution is > NOT a reasonable/natural solution in this case. Create your view in the right context (the activity's) and it will all work fine! No need to use NEW_TASK_LAUNCH. Again, this is not a hack at all, it is a very fundamental difference in semantics. When you use this flag, you are saying you want the activity to run as part of a new task, not as part of the current activity's task. You must use this flag when calling startActivity() from an application, because the application is not an activity and thus not part of an existing task. > > - Performing a cast is a quick and dirty style that you can use when > > you know exactly how your View class will be used. > Exactly, Quick & Dirty => Hack :) It's perfectly reasonable if you are just writing your own specific application and know that a particular view you have written is only going to be run inside of an activity. Heck, make your view an inner class of activity and then you can call finish() right there all you want! > > - You can give an explicitly Activity object to the view, which allows > > the view to work in all situations though it may be awkward to hook > > things up. > Yes, I have seen this also in some example code, but I never felt it > as a natural solution, it seems like a hack too. Okay then don't do it. > > - Or you can have a formal callback interface from the view, like the > > various ones used in the platform frameworks, which is the cleanest > > approach. > Can you give me a specific and relevant example reference (URL)? Look through the android.view and android.widget packages. This is used all over the place. There is nothing particularly android about it -- it's just a regular pattern of defining a callback interface, and giving an implementation of that to the view for it to call back on at the appropriate time. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

