There was no mention of an integer so not sure where that is coming from. My code is as follows:

private class initialiseServer extends AsyncTask<Void, Integer, Boolean> {
         protected void onPreExecute(){
             dialog = ProgressDialog.show(GolfCaddie.this, "",
                     "Initializing. Please wait...", true);
         }

         protected Boolean doInBackground(Void...voids) {
             Boolean expired = false;
             String installType = "";
              String retInit = "";
              String initExpDate = "";
              SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");

             // Let's get the device ID
TelephonyManager mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
             String imei = mTelephonyMgr.getDeviceId();

// Now, let's check the application to see if we have the trial or full version. if (getApplication().getPackageName().equals("com.dtwconsulting.golfcaddietrial")){
                 installType = "trial";
             } else {
                 installType = "full";
             }
             try {
                 // Construct data
String data = "code=" + imei + "&installtype=" + installType + "&apikey=" + GlobalVars.GCAPI_KEY + "&platform=" + GlobalVars.PLATFORM;

                 // Send data
URL url = new URL(GlobalVars.HOST_WAP + "initialize.php?" + data);
                 URLConnection conn = url.openConnection();

                 // Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

                 retInit = rd.readLine();
                 JSONObject initLine = new JSONObject(retInit);
                 Number initErr = initLine.getInt("errcode");
                 initExpDate = initLine.getString("expiredate");
                 rd.close();
             } catch (Exception e) {
                 e.printStackTrace();
             }
             Date expDate = null;
             Date today = new Date();

             try {
                 expDate = df.parse(initExpDate);
             } catch (ParseException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             }
             if (expDate.before(today)){
              if (installType.equals("trial")) {
                 // Trial has expired
                 expired = true;
              }
             }
             return expired;
         }

         protected void onPostExecute(Boolean result) {
             if (result = true){
AlertDialog.Builder builder = new AlertDialog.Builder(GolfCaddie.this); builder.setMessage("Your Golf Caddie trial has expired." )
                           .setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) {
                                   GolfCaddie.this.finish();
                               }
                           });
                    AlertDialog alert = builder.create();
                    builder.show();
             }

             initApp();
         }
     }
------------------------------------------------------------------------

David Williams
Check out our WebOS mobile phone app for the Palm Pre and Pixi:
<http://www.dtw-consulting.com/GolfCaddie> Golf Caddie <http://www.dtw-consulting.com/GolfCaddie> | Golf Caddie Forum <http://www.dtw-consulting.com/GolfCaddie/forum> | Golf Caddie FAQ <http://www.dtw-consulting.com/GolfCaddie/faq.html> by DTW-Consulting, Inc.



On 3/15/2011 12:55 PM, rich friedel wrote:
This has nothing to do with your issue, just nitpicking really, but unless you need an Integer for your progress in the AsyncTask you shouldn't create it.

Thus your AsyncTask should look more like
private class InitialiseServer extends AsyncTask<Void, Void, Boolean>

Also without some idea of what your code looks like you are going to have a hard time getting help.

With that said, in its simplest form the AsyncTask:
*Note: If you do it this way make sure to handle activity changes like orientation change otherwise your activity will throw an exception because it will try to dismiss the dialog when the dialog doesn't exist any longer!*

private class InitServer extends AsyncTask(Void, Void, Boolean> {
    ProgressDialog theProgress = new ProgressDialog(TheOuterClass.this);

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        this.theProgress.setMessage("Your progress message");
        this.theProgress.show();
    }

    @Override
    protected Boolean doInBackground(Void... voidArg) {
        return false;
    }

    @Override
    protected void onPostExecute(Boolean bool) {
        super.onPostExecute(bool);

        this.theProgress.dismiss();

        if ( bool ) {
            // Do something
        } else {
            // Do something else
        }
    }
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

<<inline: GClogo.png>>

Reply via email to