我正在使用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