To tackle the flip side of what Mark is saying, just to give you
another way to get it: 'new XX()' is NOT implementing a constructor --
it is calling one, but it does not implement one.'

Mark missed a point though -- a constructor without a call to super()
will always call the default super().

You can verify that by defining a class with just a private
constructor

A.java:
class A {
  private A() {}
}

class B extends A {
   B() { }
}
---

>javac c:\temp\A.java
c:\temp\A.java:6: A() has private access in A
    B() {}
                ^
1 error

You get the same result, in fact, if you take out B's constructor,
because if you don't supply any constructor at all, Java will define a
no-arg constructor for you.

Still, Mark's point #1 is valid. A do-nothing constructor is just an
invitation to later become a do-something constructor. Since Java will
supply a do-nothing constructor for you, just take it out and let it
do so.

Mark has already demonstrate that it being there will confuse
someone!  :=)

Mark: "In fact, I'm kinda surprised the activity survives not having
the activity's constructor called."

That's because Activity's constructor IS being called, as demonstrated
above.

I might hypothesize you've programmed in C++ at some point in the
distant past.... :=)

On Mar 17, 3:46 pm, Mark Murphy <mmur...@commonsware.com> wrote:
> mike wrote:
> > We're not communicating. Are you saying that the only time
> > I should do a new XX() is *only* in onCreate?
>
> No, we're definitely not communicating.
>
> As I wrote:
>
> 1. Never implement a constructor in an Activity.
>
> In Java, "implement" means "to write code".
>
> Your sample code had:
>
> public HelloActivity() {
>     }
>
> Do not do this in an Activity (or Service, for that matter). Or, as I
>
> also wrote:
>
> 2. If you choose to violate rule #1, chain to the superclass.
>
> That would mean adding a call to super() in the otherwise do-nothing
> implementation of HelloActivity().
>
> As you pointed out, these flaws did not impact the test case, but they
> could have. In fact, I'm kinda surprised the activity survives not
> having the activity's constructor called. Gotta look up Activity in the
> source code sometime to see what symptoms you'd get for doing that...
>
> > Mike, I'll look at view flipper. View.GONE would be really cumbersome
> > and inelegant
>
> :: shrug ::
>
> I think calling setContentView() outside of onCreate() is cumbersome and
> inelegant, but, to each their own.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android Consulting/App Development:http://commonsware.com/consulting

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