I need to start animation on imageview in Pre-execute and stop it in Post-execute but app force stopped.
error: Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
here is my code:
class RefreshAsync extends AsyncTask<Void, Void, Void> {
Animation anim = AnimationUtils.loadAnimation(getContext(),
R.anim.rotation);
@Override
protected Void doInBackground(Void... arg0) {
}
@Override
protected void onPostExecute(Void result) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
imageView.animate().cancel();
}
});
super.onPostExecute(result);
}
@Override
protected void onPreExecute() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
imageView.startAnimation(anim);
}
});
super.onPreExecute();
}
}
THANKS IN ADVANCE!!