在我的android應用程序中,我使用加載屏幕,由異步任務處理。在此任務的後臺執行操作時,我希望在服務器中存在升級版本時顯示警報。 可否請讓我知道,如果有任何方式,我可以在android中做到這一點。在android中的異步doinbackground顯示警報
的代碼是
公共類任務延伸的AsyncTask {
// can use UI thread here
protected void onPreExecute() {
// this.dialog.setMessage("Loading...");
prgbar.setVisibility(View.VISIBLE);
// this.dialog.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
final UpGradation upgrade=(UpGradation) ParserServiceImpl.getUpgrade(); //check this method name correctly.
if(upgrade != null)
{
try {
pInfo = getPackageManager().getPackageInfo("com.docomo.aptv", PackageManager.GET_META_DATA);
String temp = pInfo.versionName;
int pversion= pInfo.versionCode;
int upversion=Integer.parseInt(upgrade.getVersion());
Log.i("VALUE RETURNED",""+pversion);
Log.i("jayantha","version name"+pInfo.versionName);
Log.i("jayanth","version code"+pInfo.versionCode);
if(pversion!=upversion)
{
final AlertDialog alert = new AlertDialog.Builder(context).create();
alert.setTitle("Updates");
alert.setMessage("An updated version of the application is present.Do you wish to download.");
alert.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
alert.dismiss();
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(upgrade.getURL().trim()));
startActivity(i);
finish();
} });
alert.setButton2("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {
return;
}
});
alert.setIcon(R.drawable.application_icon_50x50);
alert.setCancelable(false);
alert.show();
}
}
catch (NameNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
請轉發您的建議。
感謝提前:)
對不起,它被放置測試。請檢查代碼now.Its編輯。 – Remmyabhavan 2010-11-02 05:21:44