日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

服务器时间延迟,如何处理从服务器延迟响应时间'力逼近'

發(fā)布時間:2025/3/11 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 服务器时间延迟,如何处理从服务器延迟响应时间'力逼近' 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用下面的示例代碼來執(zhí)行l(wèi)ogin過程。您可以使用AsyncTask來執(zhí)行登錄過程。

LoginActivity類,它使用AsyncTask。

在Login按一下按鈕,我executing的AsyncTask。

在登錄過程中,這將顯示一個ProgressDialog

過程完成后,駁回ProgressDialog并顯示狀態(tài)信息給用戶

類代碼:

import android.app.Activity;

import android.app.AlertDialog;

import android.app.ProgressDialog;

import android.content.DialogInterface;

import android.os.AsyncTask;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

public class LoginActivity extends Activity {

private Button login_Button = null;

private EditText userNameText = null;

private EditText passwordText = null;

private String uName = "";

private String pass = "";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.test_login);

login_Button = (Button) findViewById(R.id.cmdDoLogin);

userNameText = (EditText) findViewById(R.id.editTextUserName);

passwordText = (EditText) findViewById(R.id.editTextPassword);

login_Button.setOnClickListener(new OnClickListener() {

public void onClick(View paramView) {

uName = userNameText.getText().toString().trim();

pass = passwordText.getText().toString().trim();

if (uName.equals("") || pass.equals("")) {

Toast.makeText(LoginActivity.this,

"Fill both username and password fields",

Toast.LENGTH_SHORT).show();

} else {

new LoginActivity.DoLoginProcess().execute(); // calling the AsyncTask here

}

}

});

}

private class DoLoginProcess extends AsyncTask {

ProgressDialog pd = null;

@Override

protected void onPreExecute() {

super.onPreExecute();

pd = new ProgressDialog(LoginActivity.this);

pd.setTitle("Logging In...");

pd.setMessage("Please wait...");

pd.setCancelable(false);

pd.show();

}

@Override

protected Integer doInBackground(Void... params) {

int loginStatus = 0 ; // treat this as loginStatus. 0 = login failed; 1=login success. You can return this value to onPostExecute function

//*********************************************

// do login process over internet here. Hope you already have the code to do the login process over internet.

//*********************************************

return loginStatus;

}

@Override

protected void onPostExecute(Integer status) {

super.onPostExecute(status);

pd.dismiss(); // dismiss the progress dialog

if (status == 0) { // login failed

AlertDialog alertDialog = new AlertDialog.Builder(

LoginActivity.this).create();

alertDialog.setTitle("Error");

alertDialog.setMessage("Login failed");

alertDialog.setButton("OK",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,

int which) {

LoginActivity.this.finish();

dialog.cancel();

}

});

alertDialog.setIcon(android.R.drawable.ic_dialog_info);

alertDialog.show();

} else if(status == 1) { // login success

AlertDialog alertDialog = new AlertDialog.Builder(

LoginActivity.this).create();

alertDialog.setTitle("Success");

alertDialog.setMessage("Login success");

alertDialog.setButton("OK",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,

int which) {

LoginActivity.this.finish();

dialog.cancel();

}

});

alertDialog.setIcon(android.R.drawable.ic_dialog_info);

alertDialog.show();

}

}

}

}

的test_login布局XMl文件:

android:id="@+id/loginbglayout"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="10dp" >

android:id="@+id/holderLayout"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_centerInParent="true" >

android:id="@+id/row1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:gravity="center" >

android:id="@+id/textViewUserName"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginRight="10dp"

android:gravity="right"

android:text="UserName"

android:textColor="#ffffff" />

android:id="@+id/editTextUserName"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1" >

android:id="@+id/row2"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="10dp"

android:gravity="center" >

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginRight="10dp"

android:gravity="right"

android:text="Password"

android:textColor="#ffffff" />

android:id="@+id/editTextPassword"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:inputType="textPassword" />

android:id="@+id/row3"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="10dp"

android:gravity="center" >

android:layout_width="0dp"

android:layout_height="2dip"

android:layout_weight="1"

android:focusable="false" />

android:id="@+id/cmdDoLogin"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="right"

android:text="Login" >

總結

以上是生活随笔為你收集整理的服务器时间延迟,如何处理从服务器延迟响应时间'力逼近'的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。