从Android中的片段调用Web服务(API)的正确方法
问题描述:
我有一个包含片段和对话框的活动。我从onCreateView方法中的片段调用API。当我在片段上并打开对话框时,片段再次击中API。我想阻止它。我希望当我打开对话框时,我的应用程序不会打中。从Android中的片段调用Web服务(API)的正确方法
//代码
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_news, container, false);
callApi()
}
答
调用onViewCreated
你这样的API。
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
callApi(); //here call your function.
}
在onViewCreated – Kriti
中调用你的api时,当我从另一个activity返回frag时,再次调用api。我不想那样。任何建议! –