Header Ads

What is the first callback method in Android? When it is used?



Answer:


onCreate() is the first callback method in android.

It is used or called when the activity is first created.

If we have an application start-up logic that needs to perform only once during the life cycle of an activity, then we can write that logic in onCreate() method.

Following is the example of defining a onCreate() method in android activity.

@Override
protected void onCreate(Bundle savedInstanceState) {
    
super.onCreate(savedInstanceState);
    setContentView(R.layout.
activity_main);
}

 

Once onCreate() method execution is finished, the activity will enter into Started state and system calls the onStart() method.

No comments

Theme images by Matt Vince. Powered by Blogger.