Doinbackground Run So Fast When Using Asynctask In Fragment
I have a problem so strange when using Asynctask in fragment, In onCreate of Fragment I called AsyncTask like so: @Override public void onCreate(Bundle savedInstanceState) { //
Solution 1:
Calling new FitnessHistoryDataAsync(getActivity()).execute(10);
before super.onCreate(savedInstanceState);
is a problem you should fix first. Change it to something like this
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Step 1
new FitnessHistoryDataAsync(getActivity()).execute(10);
}
Solution 2:
It looks like the library I used also is another thread.
So, I no need to create new thread AsyncTask
.
Just edit coding like this :
Constants.SDK.getFitnessHistoryData(context, 10,
newFitnessHistoryListener() {
@OverridepublicvoidonReceiveFailed(String errorMessage) {
// Step 4 Log.i("", "error " + errorMessage);
}
@OverridepublicvoidonReceiveData(
FitnessHistory[] fitnessHistoryData) {
// Step 4 Log.i("", "onReceiveData");
// TODO Directly updated UI in here when already received new data
}
});
That's solved my issue.
Post a Comment for "Doinbackground Run So Fast When Using Asynctask In Fragment"