((Activity)getApplicationContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
This code is right? I get a trouble to think it!
((Activity)getApplicationContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
This code is right? I get a trouble to think it!
See this answer: https://stackoverflow.com/a/6760019/923441
You should definitely NOT cast getApplicationContext() to Actvity, it is not guaranteed to work and such programming will lead to crashes down the line.
runOnUiThread() it's a method from Activity so if you are on an Activity you can avoid this : ((Activity)getApplicationContext()), but if you are on a Fragment, you'll need to get the first your Activity and then call this method, otherwise you won't be able to call it.
You should change this : ((Activity)getApplicationContext())
to this :
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
It can throw you a ClassCastException as Blackbelt said in comments.