display alert inside Async doinbackground in android
<p>In my android application i am using a loading screen,processed by Async task.In do in background of this task i would like to display a alert whenever an upgraded version exist in the server.
Could you please let me know if there is any way that i can do it in android.</p>

<p>The code is </p>

<blockquote>
  <p>public class Task extends AsyncTask {</p>
</blockquote>

<pre><code>    // 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();
                    }
                }
</code></pre>

<p>Please forward your suggestions.</p>

<p>Thanks in advance :)</p>
