android activity class constructor working

前端 未结 4 2024
陌清茗
陌清茗 2021-01-01 00:58

When considering the case with android activity, the first method to work is its onCreate method..right?

Suppose i want to pass 2 parameters to android

4条回答
  •  太阳男子
    2021-01-01 01:52

    But you also can create very well a constructor of UserHome.

    public class MainActivity extends Activity {
    UserHome userHome = new UserHome(param1,param2);
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    userHome.yourMethod();
    }}
    

    Why do you think that is not possible to initialize a contructor?..MainActivity is a class like any other, just that extends Activity, but also keeps the properties of a class, so that can have, constructors, methods, members.

提交回复
热议问题