onResume for android注释

Mat*_*ane 2 android android-annotations

我正在使用android注释,并且我需要在我的activity中的onResume()函数中执行一些代码.

从android注释活动(即使用@EActivity)覆盖onResume函数是否安全?

Won*_*abo 5

是的,您应该使用这些生命周期方法,就像使用简单的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)

  • @swalkner是的.调用`@ AfterViews`时,请参阅[here](http://stackoverflow.com/a/33833912/747412). (3认同)
  • 是否可以安全地假设所有注入的视图都可以在```onResume```方法中使用? (2认同)