作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
public class NewClass extends Activity
{
public final String NAMESPACE = "**";
public final String URL = "***";
public final String SOAP_ACTION_1 = "**";
public final String METHOD_NAME_1 = "***";
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new FeaturesHomes().execute();
}
}
public class FeaturedHomes extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
mProgressDialog=ProgressDialog.show(getActivity(), "Wait", "Data Loading..");
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
if (mAllMethods.check_Internet()==true) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,60000);
try {
androidHttpTransport.call(SOAP_ACTION_1, envelope);
SoapObject mSoapObjectCompanyDetailResponse = (SoapObject)envelope.bodyIn;
Object re= null;
re = envelope.getResponse();
System.out.println("Response "+re.toString());
JSONObject mainJson = new JSONObject(re.toString());
JSONArray jsonArray = mainJson.getJSONArray(StaticValues.FeaturedCommunitiesArray);
JSONArray jArray = mainJson.getJSONArray("RateLog");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject objJson = jsonArray.getJSONObject(i);
mGetFeaturedProperty = new GetFeaturedProperty();
mGetFeaturedProperty.setResidenceID(objJson.getString(StaticValues.ResidenceId));
String s=AllMethods.MakeWord(objJson.getString(StaticValues.ResidenceTitle));
mGetFeaturedProperty.setResidenceTitle(s);
mGetFeaturedProperty.setResidenceAddressStreet(objJson.getString(StaticValues.ResidenceAddress));
mGetFeaturedProperty.setResidenceCountry(objJson.getString(StaticValues.ResidenceCountry));
mGetFeaturedProperty.setResidenceDesc(objJson.getString(StaticValues.ResidenceDesc));
mGetFeaturedProperty.setResidenceAddressPincode(objJson.getString(StaticValues.ResidencePincode));
mGetFeaturedProperty.setResidenceState(objJson.getString(StaticValues.ResidenceState));
mGetFeaturedProperty.setResidenceCity(objJson.getString(StaticValues.ResidenceCity));
mGetFeaturedProperty.setResiLatitude(objJson.getString(StaticValues.ResiLatitude));
mGetFeaturedProperty.setResiLongitude(objJson.getString(StaticValues.ResiLongitude));
mGetFeaturedProperty.setImage(objJson.getString(StaticValues.Image));
mArrayListFeaturedProperties.add(mGetFeaturedProperty);
}
for (int j = 0; j < jArray.length(); j++) {
JSONObject objJson1 = jArray.getJSONObject(j);
GetFeaturedProperty mGetFeaturedProperty1 = new GetFeaturedProperty();
mGetFeaturedProperty1.setRating(objJson1.getString("OverAllRate"));
mArrayListTempFeaturedProperties.add(mGetFeaturedProperty1);
}
} catch (Exception e) {
e.printStackTrace();
}
}
else {
mProgressDialog.dismiss();
mAllMethods.ShowDialog(getActivity(), "Validate", "Network not Available");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (mProgressDialog!=null) {
mProgressDialog.dismiss();
}
if (mAllMethods.isNetError) {
mAllMethods.ShowDialog(getActivity(), "Validation", "Your internet is slow");
}
else {
System.out.println("Rating SIze "+mArrayListTempFeaturedProperties.size());
System.out.println("Ac SIze "+mArrayListFeaturedProperties.size());
if (mArrayListFeaturedProperties.size()>0) {
mMap.clear();
for (int i = 0; i < mArrayListFeaturedProperties.size(); i++) {
MarkerOptions markerOptions = new MarkerOptions();
double lat =Double.parseDouble(mArrayListFeaturedProperties.get(i).getResiLatitude());
double lng =Double.parseDouble(mArrayListFeaturedProperties.get(i).getResiLongitude());
final LatLng latLng = new LatLng(lat,lng);
GetFeaturedProperty firstEventInfo = new GetFeaturedProperty(latLng,mArrayListFeaturedProperties.get(i).getResidenceID(),mArrayListFeaturedProperties.get(i).getResidenceTitle());
Marker firstMarker = placeMarker(firstEventInfo);
eventMarkerMap = new HashMap<Marker, GetFeaturedProperty>();
eventMarkerMap.put(firstMarker, firstEventInfo);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat ,lng), 8.0f));
}
mNewadapter=new NewCustomAdapter(getActivity(),mArrayListFeaturedProperties,mArrayListTempFeaturedProperties);
mGridView.setAdapter(mNewadapter);
}
}
}
}
AllMethdos.java
public class AllMethods {
Activity mActivity;
ConnectivityManager mConnectivityManager;
NetworkInfo mNetworkInfo ;
boolean isNetError=false;
public AllMethods() {
// TODO Auto-generated constructor stub
}
public boolean check_Internet()
{
mConnectivityManager= (ConnectivityManager) mActivity.getSystemService(Context.CONNECTIVITY_SERVICE);
mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if(mNetworkInfo != null && mNetworkInfo.isConnectedOrConnecting())
{
isNetError = false;
return true;
}
else
{
isNetError = true;
return false;
}
}
}
你好 friend ,当我运行上面的代码时有时它工作正常但是当我的设备 Internet
变慢然后它会花费很多时间所以我已经检查了条件如果有任何互联网错误然后显示对话框消息为此,但它现在不会显示并且数据未加载(意味着空白)并且 proggres 对话框关闭并给我错误消息,如
03-20 18:06:23.337: W/System.err(20648): java.net.SocketTimeoutException: failed to connect to seniorhomes.worldexplorer.ca/208.91.198.99 (port 80) after 20000ms
03-20 18:06:23.337: W/System.err(20648): at libcore.io.IoBridge.connectErrno(IoBridge.java:150)
03-20 18:06:23.337: W/System.err(20648): at libcore.io.IoBridge.connect(IoBridge.java:112)
03-20 18:06:23.337: W/System.err(20648): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
03-20 18:06:23.337: W/System.err(20648): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
03-20 18:06:23.337: W/System.err(20648): at java.net.Socket.connect(Socket.java:872)
03-20 18:06:23.347: W/System.err(20648): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:77)
03-20 18:06:23.347: W/System.err(20648): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
03-20 18:06:23.347: W/System.err(20648): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
03-20 18:06:23.347: W/System.err(20648): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
03-20 18:06:23.347: W/System.err(20648): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
03-20 18:06:23.347: W/System.err(20648): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
03-20 18:06:23.347: W/System.err(20648): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
03-20 18:06:23.347: W/System.err(20648): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
03-20 18:06:23.347: W/System.err(20648): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
03-20 18:06:23.357: W/System.err(20648): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
03-20 18:06:23.357: W/System.err(20648): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)
03-20 18:06:23.357: W/System.err(20648): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:146)
03-20 18:06:23.357: W/System.err(20648): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
03-20 18:06:23.367: W/System.err(20648): at pkg.android.rootways.retirement.JobEventDetailListActivitty$GetJobList.doInBackground(JobEventDetailListActivitty.java:405)
03-20 18:06:23.367: W/System.err(20648): at pkg.android.rootways.retirement.JobEventDetailListActivitty$GetJobList.doInBackground(JobEventDetailListActivitty.java:1)
03-20 18:06:23.367: W/System.err(20648): at android.os.AsyncTask$2.call(AsyncTask.java:264)
03-20 18:06:23.367: W/System.err(20648): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-20 18:06:23.367: W/System.err(20648): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-20 18:06:23.377: W/System.err(20648): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
03-20 18:06:23.377: W/System.err(20648): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-20 18:06:23.377: W/System.err(20648): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-20 18:06:23.377: W/System.err(20648): at java.lang.Thread.run(Thread.java:864)
最佳答案
这是由于有时您的服务器没有响应您从应用程序调用的请求,因此您取决于网络速度以及服务器速度以快速响应
关于android - 如何使用 Web 服务处理 Android 应用程序中的互联网缓慢状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22531700/
我是一名优秀的程序员,十分优秀!