How to make a callback after the view is completely rendered ?
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 :)
Try this logic ... always called after the view has got focus or rendered or looses focus
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
doWhateverAfterScreenViewIsRendered();
}
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;
};
}
I created the above class and then called this method for execution in onCreate()
LoadActivity loadactivity= new LoadActivity();
loadactivity.execute();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With