视图完全渲染后如何进行回调? [英] How to make a callback after the view is completely rendered?
问题描述
在视图完全呈现后如何进行回调?
How to make a callback after the view is completely rendered ?
我正在尝试调用一个获取父视图屏幕截图的方法。
如果我在 onCreate()
方法中编写该代码,则应用程序将由于空指针而崩溃(因为未呈现任何视图)。现在,我已经实现的
临时解决方案是在调用该方法之前延迟1秒。
但是,我正在寻找一个更强大的解决方案。
I am trying to call a method which takes a screen-shot of parent view.
If I write that code in onCreate()
method, the app crashes due to null pointer (as no view is rendered).
for now the temporary solution I have implemented is to make a delay of 1 second before calling that method.
But, I am looking for a much more robust solution to this problem.
任何建议和帮助都值得赞赏。
谢谢:)
any suggestions and help appreciated. thanks :)
推荐答案
我现在有一个更好的选择:)
这确实可以打电话呈现布局后返回
I have got a better option now :) this really gives a call-back after the layout is rendered
private class LoadActivity extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
mainMethod();
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
takeScreenShot(1);
}
@Override
protected String doInBackground(String... params) {
return null;
};
}
我创建了上面的类,然后在onCreate()中调用此方法来执行
I created the above class and then called this method for execution in onCreate()
LoadActivity loadactivity= new LoadActivity();
loadactivity.execute();
这篇关于视图完全渲染后如何进行回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!