简体   繁体   中英

How do I initiate a method within main activity from an onInit?

I need to know code to fix my example below to initiate a method within my activity.

Code:

 public void onInit(int status) {

     HowDoIStartThisMethodCorrectly?(); <-- because this doesn't start that method.

}

I need a method within my main activity to run when program starts, so I add to onCreate my onInit method, but it's not working.

Only the code in onCreate() is guaranteed to run:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    PUTYOURMETHODHERE();

} 

Or you could do:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    onInit();

} 

public void onInit() {

    HowDoIStartThisMethodCorrectly?(); <-- because this doesn't start that method.

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM