简体   繁体   English

在活动生命周期的哪一部分中,会调用各种android注释?

[英]During what part of activity life cycle various android annotations are called?

Currently I am moving my android project to android-annotations. 目前,我正在将我的android项目移至android-annotations。 I am having difficulty in understanding the sequence in which annotations are called. 我很难理解注释的调用顺序。 Due to wrong sequence I am getting nullPointerExceptions. 由于顺序错误,我得到了nullPointerExceptions。

As an example usecase, I am trying to use @ViewById in Fragment. 作为一个示例用例,我试图在Fragment中使用@ViewById。 However I am getting nullPointerException in onCreateView() and onResume(). 但是我在onCreateView()和onResume()中得到nullPointerException。

Documentation explaining about at what time in activity life cycle, which annotation will be triggered will be very helpful. 说明活动生命周期中的什么时间,将触发哪个注释的文档将非常有帮助。

Following is small section of my code :- 以下是我的代码的一小部分:-

@EFragment
public class DiscoverFragment extends Fragment {
    @ViewById(R.id.dishList)
    PullToRefreshListView mPullToRefreshView;

    @ViewById
    LinearLayout noDataAvailable;

    @ViewById
    LinearLayout dataAvailable;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.d(TAG, "onCreateView");
        View v = inflater.inflate(R.layout.fragment_discover, container, false);

        if (cursorStringDistance == null) {
            mPullToRefreshView.setMode(Mode.PULL_FROM_START);
            mPullToRefreshView.setOnRefreshListener(oneRefresher);
        } else {
            mPullToRefreshView.setMode(Mode.BOTH);
            mPullToRefreshView.setOnRefreshListener(bothRefresher);
        }

        ListView actualListView = mPullToRefreshView.getRefreshableView();
        actualListView.setAdapter(mAdapter);
        return v;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (dishListDistance.size() == 0) {
            noDataAvailable.setVisibility(View.VISIBLE);
            dataAvailable.setVisibility(View.GONE);
        } else {
            noDataAvailable.setVisibility(View.GONE);
            dataAvailable.setVisibility(View.VISIBLE);
        }
        startTime = System.currentTimeMillis();
    }
}

I am getting nullPointerException for line mPullToRefreshView.setMode(Mode.PULL_FROM_START); 我正在行mPullToRefreshView.setMode(Mode.PULL_FROM_START);获得nullPointerException mPullToRefreshView.setMode(Mode.PULL_FROM_START); and noDataAvailable.setVisibility(View.VISIBLE); noDataAvailable.setVisibility(View.VISIBLE); .

You have to add an @AfterViews annotated method, the injected View fields will be available there. 您必须添加一个@AfterViews注释方法,注入的View字段将在那里可用。 In case of Fragment s AA injects the View fields in the onViewCreated() method. 对于Fragment AA会在onViewCreated()方法中注入View字段。 If you want to understand the lifecycle, inspect the generated class. 如果您想了解生命周期,请检查生成的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM