1.Iam fetching Bulk of Data from Server and Inserting in the Local Database While Login in android.
2.For Syncing Purpose i have Used Retrofit Library, Syncing and Inserting Working Fine.
My Problem: While Syncing Bunch of Data from server Using Retrofit ,Circle Progress Dialog Getting Freeze.
Help me how to Fix this Issue.
EDIT:1
Called Retrofit method inside Async task ,Still Circle ProgressDialog Getting Freeze
//Calling the Async Task
Asynctask_Getdata task=new Asynctask_Getdata(TokenType_StringValue,Access_Token_StringValue, ID_StringValue);
task.execute();
//AsyncTask MEthod
public class Asynctask_Getdata extends AsyncTask<String,Void,Void>
{
String TokenType_StringValueitem;
String Access_Token_StringValueitem;
String ID_StringValueitem;
public Asynctask_Getdata(String tokenType_StringValueitem, String access_Token_StringValueitem, String ID_StringValueitem) {
TokenType_StringValueitem = tokenType_StringValueitem;
Access_Token_StringValueitem = access_Token_StringValueitem;
ID_StringValueitem = ID_StringValueitem;
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
if (!pDialog.isShowing())
{
pDialog.setIndeterminate(true);
pDialog.setCanceledOnTouchOutside(false);
pDialog.setMessage("Please Wait Getting Data...");
pDialog.show();
}
}
@Override
protected void onPostExecute(Void aVoid)
{
super.onPostExecute(aVoid);
}
@Override
protected Void doInBackground(String... params)
{
getLoginDataCall(TokenType_StringValueitem, Access_Token_StringValueitem, ID_StringValueitem );
return null;
}
}
private void getLoginDataCall(String TokenType_String, String Access_Token_StringValue, String RouteID_String) {
String Tokenadd = TokenType_String + " Access_Token_StringValue;
sisClient.getApi().getAllData(Tokenadd, RouteID_String,
new Callback<CommonResponse>() {
@Override
public void success(CommonResponse commonResponse, Response response) {
Timber.d("sendOtpAPICall%s", commonResponse.getStatusCode());
switch (commonResponse.getStatusCode()) {
case 200:
try {
JSONArray jsonarray = null;
try {
jsonarray = new JSONArray(commonResponse.getRouteMaster());
if (!commonResponse.getRouteMaster().equals("[]"))
{
for (int i = 0; i < jsonarray.length(); i++)
{
JSONObject jsonobject = jsonarray.getJSONObject(i);
RouteId_StringValue = jsonobject.getString("RouteId");
Asynxfor_Route_Master_insert(RouteId_StringValue);
}
} else {
System.out.println("ROute Master Is NULL ::" + commonResponse.getStatusMessage() + "\n");
}
} catch (Exception e) {
e.printStackTrace();
;
}
break;
case 404:
pDialog.dismiss();
Toast.makeText(LoginPage.this, R.string.wrong_Username_or_password, Toast.LENGTH_LONG).show();
break;
case 500:
pDialog.dismiss();
Toast.makeText(LoginPage.this, R.string.something_wrong, Toast.LENGTH_LONG).show();
break;
}
}
@Override
public void failure(RetrofitError error) {
try {
if (error != null) {
pDialog.dismiss();
Timber.i("sendOtpAPICall error %s", error.getResponse().getStatus());
String json = new String(((TypedByteArray) error.getResponse().getBody()).getBytes());
Timber.i("failure error %s", json.toString());
JSONObject json1 = new JSONObject(json.toString());
String json1string = json1.getString("StatusMessage");
switch (error.getResponse().getStatus()) {
case 404:
Toast.makeText(getApplicationContext(), R.string.wrong_Username_or_password, Toast.LENGTH_LONG).show();
break;
case 500:
Toast.makeText(LoginPage.this, R.string.something_wrong, Toast.LENGTH_LONG).show();
break;
default:
Toast.makeText(LoginPage.this, json1string, Toast.LENGTH_LONG).show();
break;
}
} else {
Timber.i("failure error %s", "Recieving error null rom server");
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(LoginPage.this, R.string.something_wrong, Toast.LENGTH_LONG).show();
}
}
});
}
execute
method of your asyncTask? can you show the part of code? – Clipper