Why I cannot pass parameters to Android Activity Constructor

I'm surprised that nobody answered the actual question asked! So to answer this Why I cannot pass parameters to Android Activity Constructor: because Android calls the constructor of the Activity and the only constructor Android calls is the default constructor which of course you can override but "It doesn't matter whether you add it or not, and there is no context in which it can be employed in a useful way.".

So as there is no way you can pass your parameters to default constructor, you cannot employ it to work for you.


Refer to your code:

CalorieSelectorActivity csa = new CalorieSelectorActivity(userName);

Intent i = new Intent(thisContext, csa.getClass());

startActivity(i);

Even if you create an object of your activity, what you are "passing" in the Intent object is not the activity object but just the class of your activity. In startActivity() the Android framework will try to instantiate an object of your activity. And it calls the default constructor (without parameters) when it does that. It fails when your class does not have a constructor without parameters.

Of course, you have found the correct solution, pass the parameters as part of Intent object.