Home > OS >  Open an activity via intent or via instance
Open an activity via intent or via instance

Time:09-23

I have a class REG that extends Activity: it has a window, buttons, actions, etc. I know how to open the activity via an Intent.

Yet, I could also make a new instance of the class:

new REG(...)

When/why I should use one over the other?

CodePudding user response:

Yet, I could also make a new instance of the class

Not really.

When/why I should use one over the other?

You always start activities via startActivity(), whether you are calling it yourself or something else is calling it on your behalf.

Using the constructor creates the object, but it will not be properly initialized, nor will it show a UI. Never create an instance of an activity (or service or ContentProvider) directly yourself.

  • Related