问题
I want to call a method as soon as the activity has loaded. The method is a public void. Any help would be appreciated
回答1:
You can use the following method
You can call your method in between any one of them on Activity startup all these are called where as onResume is called every time activity resumes it is well explained in ActivityLifeCycle Diagram
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
}
@Override
protected void onStart()
{
// TODO Auto-generated method stub
super.onStart();
}
@Override
protected void onResume()
{
// TODO Auto-generated method stub
super.onResume();
}
You can learn more from here
You can learn more from ActivityLifeCycle
or follow this ActivityLifeCycle
回答2:
You have to call the method in the onCreate() method. The onCreate() method is called when the activity is first created. Check out the Activity lifecycle:
回答3:
You can view the activity timeline Here, and check out the startActivity() function Here.
Hopefully these two will lead you in the right direction for your situation. Good luck.
来源:https://stackoverflow.com/questions/18703841/call-method-on-activity-load-android