我有一个要从onCreate调用的方法,然后当该方法完成时调用另一个方法。
这可能不是最佳方法,所以如果有更简单的方法,请告诉我!

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_view_my_tickets);
//I want to execute firstMethod from in here
}


public void firstMethod(){

     //code I want to execute on create
  //Only when this is finished- I want to execute secondMethod


 }

public void secondMethod(){

//only executed when firstMethod is finished

}

最佳答案

这是一个简单的过程:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_view_my_tickets);
//I want to execute firstMethod from in here
firstMethod();
secondMethod();
}


为确保此功能完美无误地工作,请确保您的firstMethod()不涉及任何线程。

来自@codeMagic的注释的更新:


  从firstMethod()调用secondMethod()

07-26 07:13