我正在使用android批註,並且需要在我的活動中的onResume()函數中執行一些代碼。onResume for android註釋
從android註釋活動(即使用@EActivity)重寫onResume函數是否安全?
我正在使用android批註,並且需要在我的活動中的onResume()函數中執行一些代碼。onResume for android註釋
從android註釋活動(即使用@EActivity)重寫onResume函數是否安全?
呀,你應該使用這些生命週期方法就像用普通的Android活動。有一兩件事,但:injected View
s尚未在onCreate
可用的方法,這就是爲什麼@AfterViews
存在:
@EActivity(R.layout.views_injected)
public class ViewsInjectedActivity extends Activity {
@ViewById
Button myButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// myButton is not yet available here
}
@AfterViews
void setupViews() {
// myButton is first available here
myButton.setText("Hello");
}
@Override
protected void onResume() {
super.onResume();
// just as usual
}
}
是的。只需撥打super.onResume()
然後添加您的代碼。
我這樣做只是想他們在這裏創建例如:https://github.com/excilys/androidannotations/wiki/Enhance-activities
是安全的假設所有注入的觀點是在'''onResume'''方法可用? – swalkner
@swalkner是的。當調用'@ AfterViews'時,請參閱[這裏](http://stackoverflow.com/a/33833912/747412)。 – WonderCsabo
我對此一無所知,但我對這裏的文檔有了一個線索:''@AfterViews每次調用setContentView()都會被調用。 (僅限活動)'''。然後,如果在設置內容後調用@Afterviews,則表示onCreate已完成,然後生命週期的下一步是onResume https://github.com/excilys/androidannotations/wiki/%40AfterXXX-call-order – cutiko