Mat*_*ane 2 android android-annotations
我正在使用android注释,并且我需要在我的activity中的onResume()函数中执行一些代码.
从android注释活动(即使用@EActivity)覆盖onResume函数是否安全?
是的,您应该使用这些生命周期方法,就像使用简单的Android活动一样.但有一点是:注入的Views 在你的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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2024 次 |
| 最近记录: |