2013-12-06 4 views
0

Я делаю вход в систему, в этом я использую три кнопки, в то время как нажмите кнопку «Логин», я вызываю диалог оповещений, где я использую XML-файл SignIn для макета для менеджера alertdialog, где я использую два текстовое поле для имени пользователя & Пароль & кнопку, когда нажмите на кнопку, то вызвать класс, который расширяет AsyncTask класс, там я использовать Shared Prefernce & Json для входа, но в LogCat ошибка приходит, что этоКак вызвать класс, который расширяет класс Asynctask от AlertDialogManager

AndroidRuntime(6179): FATAL EXCEPTION: main 
AndroidRuntime(6179): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application 
AndroidRuntime(6179): at android.view.ViewRoot.setView(ViewRoot.java:531) 
AndroidRuntime(6179): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177) 
AndroidRuntime(6179): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 
AndroidRuntime(6179): at android.app.Dialog.show(Dialog.java:241) 
AndroidRuntime(6179): at com.example.ReferenceRewards.LogInActivity$BackgroundTask.onPreExecute(LogInActivity.java:489) 
AndroidRuntime(6179): at android.os.AsyncTask.execute(AsyncTask.java:391) 
AndroidRuntime(6179): at com.example.ReferenceRewards.LogInActivity$2.onClick(LogInActivity.java:156) 
/AndroidRuntime(6179): at android.view.View.performClick(View.java:2485) 
AndroidRuntime(6179): at android.view.View$PerformClick.run(View.java:9080) 
AndroidRuntime(6179): at android.os.Handler.handleCallback(Handler.java:587) 
AndroidRuntime(6179): at android.os.Handler.dispatchMessage(Handler.java:92) 
AndroidRuntime(6179): at android.os.Looper.loop(Looper.java:123) 
AndroidRuntime(6179): at android.app.ActivityThread.main(ActivityThread.java:3683) 
AndroidRuntime(6179): at java.lang.reflect.Method.invokeNative(Native Method) 
AndroidRuntime(6179): at java.lang.reflect.Method.invoke(Method.java:507) 
AndroidRuntime(6179): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
AndroidRuntime(6179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
AndroidRuntime(6179): at dalvik.system.NativeStart.main(Native Method) 

// & Мой вход Активность Класс кода

package com.example.ReferenceRewards; 


import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.InputStreamReader; 
import java.net.URLEncoder; 
import java.security.PublicKey; 

import org.apache.http.HttpEntity; 
import org.apache.http.HttpResponse; 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.methods.HttpGet; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.json.JSONException; 
import org.json.JSONObject; 


import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Dialog; 
import android.app.ProgressDialog; 
import android.content.Context; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.text.SpannableString; 
import android.text.style.UnderlineSpan; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ImageView; 
import android.widget.TextView; 
import android.widget.Toast; 

public class LogInActivity extends Activity{ 
    ImageView imagereferencerewards; 
    TextView txtview,forgot_pass; 
    Button btnsignin; 
    Button btnjoinus; 
    Button btnloginwithfb; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.login); 
     imagereferencerewards = (ImageView)findViewById(R.id.splash_icon); 
     txtview = (TextView)findViewById(R.id.textView1); 
     btnsignin =(Button)findViewById(R.id.btnsignin); 
     btnjoinus =(Button)findViewById(R.id.btnjoinus); 
     btnloginwithfb=(Button)findViewById(R.id.btnloginusingfb); 
     forgot_pass =(TextView)findViewById(R.id.forgot_pass); 

     SpannableString fpContent = new SpannableString("Forgot your password?"); 
     fpContent.setSpan(new UnderlineSpan(), 0, fpContent.length(), 0); 
     forgot_pass.setText(fpContent); 


     forgot_pass.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Toast.makeText(getApplicationContext(), "forgot password,enter mail id & Mobile No ", Toast.LENGTH_SHORT).show(); 
       final Dialog d = new Dialog(getApplicationContext()); 
       d.setContentView(R.layout.forgotpassword); 
       d.setTitle("FORGOT YOUR PASSWORD"); 
       d.setCancelable(true); 
       EditText edtfemail=(EditText) d.findViewById(R.id.edtfemail); 
       EditText edtfmob = (EditText) d.findViewById(R.id.edtfmobile); 
       Button btnfsubmit =(Button) d.findViewById(R.id.btnfsubmit); 
       btnfsubmit.setOnClickListener(new View.OnClickListener() { 

        @Override 
        public void onClick(View v) { 
         // TODO Auto-generated method stub 
         d.dismiss(); 
        } 
       }); 
       d.show(); 
      } 
     }); 

    } 

     public void signin(View v) { 



      final AlertDialogManager alert = new AlertDialogManager(); 
      //SessionManager session = new SessionManager(getApplicationContext()); 
      String TAG = "LOGINACTIVITY"; 
      final ConnectionDetector cd; 
      final SharedPreferences pref; 

      final String TAG_USER_ID = "userId"; 

      cd = new ConnectionDetector(this); 
      pref = LogInActivity.this.getSharedPreferences(LogInActivity.this 
        .getResources().getString(R.string.pref_title), 
        Context.MODE_PRIVATE); 
      final Dialog d = new Dialog(this); 

       d.setContentView(R.layout.signin); 

       d.setTitle("SIGN IN"); 

       d.setCancelable(true); 

       final EditText edtEmail = (EditText) d.findViewById(R.id.edtemail); 

       final EditText edtPass = (EditText) d.findViewById(R.id.edtpassword); 

       try { 
        edtEmail.setText(pref.getString(this.getResources() 
          .getString(R.string.pref_username), "")); 
        edtPass.setText(pref.getString(this.getResources() 
          .getString(R.string.pref_password), "")); 

      } catch (Exception e) { 
       // TODO: handle exception 
       Log.v(TAG, "-ERROR-LINE NO "); 
      } 

       Button b = (Button) d.findViewById(R.id.btnsubmit); 

       b.setOnClickListener(new View.OnClickListener() { 

        public void onClick(View v) { 

        // Get username, password from EditText 
         //String username = edtEmail.getText().toString(); 
         //String password = edtPass.getText().toString(); 


         //if(username.trim().length() > 0 && password.trim().length() > 0) 
         if (edtEmail.getText().toString().trim().equals("")) 
         { 
          edtEmail.setError("Username required"); 
          edtEmail.requestFocus(); 
         } else if (edtPass.getText().toString().trim().equals("")) { 
          edtPass.setError("Password required"); 
          edtPass.requestFocus(); 
         } else { 

          //if (cd.isConnectingToInternet()) { 
          if(cd.isConnectingToInternet()){ 
           new BackgroundTask().execute(""); 

           /* 
           * Intent i = new Intent(LoginActivity.this, 
           * HomeActivity.class); startActivity(i); finish(); 
           */ 

          } 
         else 
         { 
           showAlertDialog(getBaseContext(), "No Internet Connection", 
             "Please connect to internet.", false); 
          } 
         } 

        } 

       }); 



       // 
       /*class BackgroundTask extends AsyncTask<String, Void, String> { 

       @Override 
       protected String doInBackground(String... params) { 
        // TODO Auto-generated method stub 
        return null; 
       } 

        }*/ 

/*    @SuppressLint("CommitPrefEdits") 
      private class BackgroundTask extends AsyncTask<String, Void, String>{ 

        ProgressDialog pd = new ProgressDialog(getBaseContext()); 

        @Override 
        protected String doInBackground(String... urls) { 
         // TODO Auto-generated method stub 
         String result =null; 
         String url=""; 
         HttpClient httpclient= new DefaultHttpClient(); 
         try { 

          url=getBaseContext().getResources().getString(R.string.base_url) 
            + "login?username=" 
            + URLEncoder.encode(edtEmail.getText().toString() 
              .trim(), "utf-8") 
            + "&password=" 
            + URLEncoder.encode(edtPass.getText().toString() 
              .trim(), "utf-8"); 
          HttpGet httpget = new HttpGet(url); 
          Log.v("LOGIN-URL", url); 

          HttpResponse httpresponse = httpclient.execute(httpget); 
          Log.i("LoginActivity", httpresponse.getStatusLine().toString()); 

          HttpEntity httpentity = httpresponse.getEntity(); 

          /*if (entity != null) { 
           // A Simple JSON Response Read 
           InputStream instream = entity.getContent(); 
           result = convertStreamToString(instream); 
           // now you have the string representation of the HTML 
           // request 
           instream.close(); 
          } 
          if(httpentity != null){ 

           InputStream is = httpentity.getContent(); 
           result = convertStreamToString(is); 
           is.close(); 
          } 

         } catch (Exception e) { 
          // TODO: handle exception 
         } 
         //return null; 
         return result; 
        } 

        private String convertStreamToString(InputStream is) { 
         // TODO Auto-generated method stub 
         //return null; 

         BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 
         StringBuilder sb = new StringBuilder(); 
         String line = null; 
         try { 
          while ((line = reader.readLine()) != null) { 
           sb.append(line + "\n"); 
          } 
         } catch (IOException e) { 
          // TODO: handle exception 
          e.printStackTrace(); 
         }finally { 
          try { 
           is.close(); 
          } catch (IOException e2) { 
           // TODO: handle exception 
           e2.printStackTrace(); 
          } 
         } 
         return sb.toString(); 
        } 

        @Override 
        protected void onPostExecute(String result) { 
         // TODO Auto-generated method stub 
         //super.onPostExecute(result); 
         pd.cancel(); 
         if (result!= null) { 
          Log.v("Login Response", "" + result); 
          int userId = 0; 
          JSONObject resultObj; 
          try { 
           resultObj = new JSONObject(result); 
           JSONObject referencerewardsObject = resultObj 
             .getJSONObject("referencerewardsSignIn"); 

           userId = referencerewardsObject.getInt(TAG_USER_ID); 

           Log.v(TAG_USER_ID, "" + userId); 

           if (userId <= 0) { 
            showAlertDialog(context, "Failure", "Not Valid User", 
              false); 
           } else { 

            SharedPreferences.Editor editor = pref.edit(); 
            if (staySignedInCheckBox.isChecked()) { 
             editor.putString(
               context.getResources().getString(
                 R.string.pref_stay_signed_in), 
               "Yes"); 
           if (userId<0) { 
            showAlertDialog(getBaseContext(), "FAILURE", "Not Valid User", false); 
           } else { 
            SharedPreferences.Editor editor = pref.edit(); 

            editor.putString(
              getBaseContext().getResources().getString(
                R.string.pref_userId), 
              String.valueOf(userId)); 
            editor.commit(); 

            Intent HomeDashIntent = new Intent(LogInActivity.this, 
              HomeDashBoard.class); 
            startActivity(HomeDashIntent); 
            finish(); 

           } 

          } catch (JSONException e) { 
           // TODO: handle exception 
           e.printStackTrace(); 
          } 
         } 
         else if (result == null) { 
           showAlertDialog(getBaseContext(), "Failure", 
             "Wrong Username or Password.", false); 
          } 
        } 

        @Override 
        protected void onPreExecute() { 
         // TODO Auto-generated method stub 

         pd.setTitle("Plaese wait"); 
         pd.setMessage("Signng In..."); 
         pd.setCancelable(true); 
         pd.show(); 

        } 

       } */ 


      // 
       d.show(); 

      } 

     private class BackgroundTask extends AsyncTask<String, Void, String> 
     { 
      ProgressDialog pd = new ProgressDialog(getBaseContext()); 

      SharedPreferences pref; 

      static final String TAG_USER_ID = "userId"; 

      //LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      /*LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      View v = inflater.inflate(R.layout.signin,null, true); 
      void setContentView(v);*/ 

      @Override 
      protected String doInBackground(String... urls) { 
       // TODO Auto-generated method stub 
       //return null; 
       setContentView(R.layout.signin); 
       EditText edtEmail = (EditText) findViewById(R.id.edtemail); 

       EditText edtPass = (EditText) findViewById(R.id.edtpassword); 
       String result =null; 
       String url=""; 
       HttpClient httpclient= new DefaultHttpClient(); 
       try { 

        url=getApplicationContext().getResources().getString(R.string.base_url) 
          + "login?username=" 
          + URLEncoder.encode(edtEmail.getText().toString() 
            .trim(), "utf-8") 
          + "&password=" 
          + URLEncoder.encode(edtPass.getText().toString() 
            .trim(), "utf-8"); 
        HttpGet httpget = new HttpGet(url); 
        Log.v("LOGIN-URL", url); 

        HttpResponse httpresponse = httpclient.execute(httpget); 
        Log.i("LoginActivity", httpresponse.getStatusLine().toString()); 

        HttpEntity httpentity = httpresponse.getEntity(); 

        /*if (entity != null) { 
         // A Simple JSON Response Read 
         InputStream instream = entity.getContent(); 
         result = convertStreamToString(instream); 
         // now you have the string representation of the HTML 
         // request 
         instream.close(); 
        }*/ 
        if(httpentity != null){ 

         InputStream is = httpentity.getContent(); 
         result = convertStreamToString(is); 
         is.close(); 
        } 

       } catch (Exception e) { 
        // TODO: handle exception 
       } 
       //return null; 
       return result; 


      } 

      private String convertStreamToString(InputStream is) { 
       // TODO Auto-generated method stub 
       //return null; 

       BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 
       StringBuilder sb = new StringBuilder(); 
       String line = null; 
       try { 
        while ((line = reader.readLine()) != null) { 
         sb.append(line + "\n"); 
        } 
       } catch (IOException e) { 
        // TODO: handle exception 
        e.printStackTrace(); 
       }finally { 
        try { 
         is.close(); 
        } catch (IOException e2) { 
         // TODO: handle exception 
         e2.printStackTrace(); 
        } 
       } 
       return sb.toString(); 
      } 

      @Override 
      protected void onPostExecute(String result) { 
       // TODO Auto-generated method stub 
       //super.onPostExecute(result); 
       // 
       pd.cancel(); 
       if (result!= null) { 
        Log.v("Login Response", "" + result); 
        int userId = 0; 
        JSONObject resultObj; 
        try { 
         resultObj = new JSONObject(result); 
         JSONObject referencerewardsObject = resultObj 
           .getJSONObject("referencerewardsSignIn"); 

         userId = referencerewardsObject.getInt(TAG_USER_ID); 

         Log.v(TAG_USER_ID, "" + userId); 


         if (userId<0) { 
          showAlertDialog(getBaseContext(), "FAILURE", "Not Valid User", false); 
         } else { 
          SharedPreferences.Editor editor = pref.edit(); 

          editor.putString(
            getBaseContext().getResources().getString(
              R.string.pref_userId), 
            String.valueOf(userId)); 
          editor.commit(); 

          Intent HomeDashIntent = new Intent(LogInActivity.this, 
            HomeDashBoard.class); 
          startActivity(HomeDashIntent); 
          finish(); 

         } 

        } catch (JSONException e) { 
         // TODO: handle exception 
         e.printStackTrace(); 
        } 
       } 
       else if (result == null) { 
         showAlertDialog(getBaseContext(), "Failure", 
           "Wrong Username or Password.", false); 
        } 

       // 
      } 

      @Override 
      protected void onPreExecute() { 
       // TODO Auto-generated method stub 
       //super.onPreExecute(); 
       //setContentView(R.layout.signin); 
       pd.setTitle("Plaese wait"); 
       pd.setMessage("Signng In..."); 
       pd.setCancelable(true); 
       pd.show(); 

      } 

     } 


     @SuppressWarnings("deprecation") 
     public void showAlertDialog(Context context, String title, String message, 
       Boolean status) { 
      AlertDialog alertDialog = new AlertDialog.Builder(context).create(); 
      alertDialog.setTitle(title); 
      alertDialog.setMessage(message); 
      // Setting alert dialog icon 
      // alertDialog.setIcon((status) ? R.drawable.success : 
      // R.drawable.fail); 

      alertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 

       } 
      }); 
      alertDialog.show(); 
     } 



     public void joinus(View v) { 

      final Dialog d = new Dialog(this); 
      d.setContentView(R.layout.signup); 
      d.setTitle("JOIN US"); 
      d.setCancelable(true); 

      EditText edtname=(EditText) d.findViewById(R.id.edtname); 
      EditText edtaddress=(EditText) d.findViewById(R.id.edtaddress); 
      EditText edtpass=(EditText) d.findViewById(R.id.edtpassword); 
      EditText edtcity=(EditText) d.findViewById(R.id.edtcity); 
      EditText edtmobile=(EditText) d.findViewById(R.id.edtmobile); 
      Button b = (Button) d.findViewById(R.id.btnsignup); 

      b.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        d.dismiss(); 

       } 
      }); 
      d.show(); 

     } 

     /*public void forgotpassword(View v) { 

      final Dialog d = new Dialog(getApplicationContext()); 
      d.setContentView(R.layout.forgotpassword); 
      d.setTitle("FORGOT YOUR PASSWORD"); 
      d.setCancelable(true); 
      EditText edtfemail=(EditText) d.findViewById(R.id.edtfemail); 
      EditText edtfmob = (EditText) d.findViewById(R.id.edtfmobile); 
      Button btnfsubmit =(Button) d.findViewById(R.id.btnfsubmit); 
      btnfsubmit.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        d.dismiss(); 
       } 
      }); 
      d.show(); 
     }*/ 

     /*public void loginwtfb(View v) { 
      final Dialog d = new Dialog(this); 
      d.setContentView(R.layout.forgotpassword); 
      d.setTitle("FORGOT YOUR PASSWORD"); 
      d.setCancelable(true); 
      EditText edtemail=(EditText) d.findViewById(R.id.edtfemail); 
      EditText edtmob=(EditText) d.findViewById(R.id.edtfmobile); 
      Button btnfsub = (Button) d.findViewById(R.id.btnfsubmit); 

      btnfsub.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        d.dismiss(); 
       } 
      }); 
      d.show(); 
     }*/ 



} 
// & XML file of Login is 
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 


       <LinearLayout`enter code here` 
      android:layout_width="fill_parent"`enter code here` 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:paddingBottom="10dp" 
      android:paddingTop="10dp" > 

      <ImageView 
       android:id="@+id/splash_icon" 
       android:layout_width="100dp" 
       android:layout_height="100dp" 
       android:background="@drawable/logo" 
       android:contentDescription="@string/empty_string" 
       android:scaleType="fitXY" /> 
     </LinearLayout> 


    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="110dp" 
     android:text="SIGN UP-SELECT SHOP-SHOP-REPORT-GET PAID!!!" /> 

    <Button 
     android:id="@+id/btnsignin" 
     android:layout_width="250dp" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/btnjoinus" 
     android:layout_alignRight="@+id/btnjoinus" 
     android:layout_below="@+id/imageView1" 
     android:layout_marginTop="150dp" 
     android:onClick="signin" 
     android:text="SIGN IN" /> 

    <Button 
     android:id="@+id/btnjoinus" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/btnloginusingfb" 
     android:layout_alignRight="@+id/btnloginusingfb" 
     android:layout_below="@+id/btnsignin" 
     android:layout_marginTop="10dp" 
     android:onClick="joinus" 
     android:text="JOIN US" /> 

    <Button 
     android:id="@+id/btnloginusingfb" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView1" 
     android:layout_below="@+id/btnjoinus" 
     android:layout_marginTop="10dp" 
     android:layout_marginLeft="25dp" 
     android:layout_marginRight="25dp" 
     android:background="@drawable/facebook" 
     android:onClick="loginwtfb"/> 

         <TextView 
          android:id="@+id/forgot_pass" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_alignRight="@+id/btnjoinus" 
          android:layout_below="@+id/btnloginusingfb" 
          android:layout_marginTop="14dp" 
          android:text="@string/forgot_your_password" 
          android:textColor="@color/links_color" 
          android:textSize="14sp" /> 

</RelativeLayout> 
// & XML file for sign up is 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="300dp" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <EditText 
     android:id="@+id/edtemail" 
     android:layout_width="280dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:hint="Email" 
     android:ems="10" > 
     </EditText> 

     <EditText 
     android:id="@+id/edtpassword" 
     android:layout_width="280dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:hint="Password" 
     android:ems="10" > 
     </EditText> 


      <Button 
     android:id="@+id/btnsubmit" 
     android:layout_width="230dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="30dp" 
     android:layout_marginRight="30dp" 
     android:text="SUBMIT" /> 



</LinearLayout> 

ответ

0

Попробуйте это за беспокойство

new BackgroundTask().execute(); 

И поставить диалоговый код прогресса в PreExecute(), как этого

@Override 
     protected void onPreExecute() { 
      // TODO Auto-generated method stub 
      super.onPreExecute(); 

      pDialog = new ProgressDialog(getParent()); 
      pDialog.setMessage("Please wait ..."); 
      pDialog.setIndeterminate(false); 
      pDialog.setCancelable(false); 
      pDialog.show(); 
     } 

UDATE ::

Использование AsyncTaskClass в

залежи
class HttpAsyncTask extends AsyncTask<String, Void, String> { 

     @Override 
     protected void onPreExecute() { 
      // TODO Auto-generated method stub 
      super.onPreExecute(); 

      pDialog = new ProgressDialog(getParent()); 
      pDialog.setMessage("Please wait ..."); 
      pDialog.setIndeterminate(false); 
      pDialog.setCancelable(false); 
      pDialog.show(); 
     } 

     @Override 
     protected String doInBackground(String... params) { 
      // TODO Auto-generated method stub 

      httpclient = new DefaultHttpClient(); 
      httpget = new HttpGet(StaticVars.all_service_url); 

      try { 
       httpresponse = httpclient.execute(httpget); 
       System.out.println("httpresponse" + httpresponse); 

       is = httpresponse.getEntity().getContent(); 
       isr = new InputStreamReader(is); 
       br = new BufferedReader(isr); 
       sb = new StringBuilder(); 

       String recievingDataFromServer = null; 
       while ((recievingDataFromServer = br.readLine()) != null) { 
        Log.i("CHECK WHILE", "CHECK WHILE"); 
        sb.append(recievingDataFromServer); 
       } 

       myJsonString = sb.toString(); 

       SharedPreferences sp = getSharedPreferences("modify", 0); 
       SharedPreferences.Editor editor = sp.edit(); 
       editor.putString("myJsonString", myJsonString); 

       editor.commit(); 

      } catch (ClientProtocolException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

      return null; 
     } 

     @Override 
     protected void onPostExecute(String result) { 
      // TODO Auto-generated method stub 
      super.onPostExecute(result); 

      if (myJsonString.length() > 0) { 

       try { 

        myJsonObject = new JSONObject(myJsonString); 
        myJsonArray = myJsonObject.getJSONArray("keyword"); 

        for (int i = 0; i < myJsonArray.length(); i++) { 

         JSONObject objJson = myJsonArray.getJSONObject(i); 
         name = objJson.getString("name"); 

         recognition_id = objJson.getInt("recognition_id"); 
         ServicesModel sm = new ServicesModel(); 
         //name = name.replaceAll(name, "<font color='red'>$0</font>"); 
         /*Pattern pattern = Pattern.compile(etselect.getText().toString(), Pattern.CASE_INSENSITIVE); 
         Matcher matcher = pattern.matcher(name); 
         name = matcher.replaceAll("\0");*/ 

         sm.name = name; 
         sm.recognisationId = recognition_id; 
         sm.recognisationName = recognisationArray[recognition_id]; 
         serviceArray.add(sm); 
         /*if(Arrays.asList(serviceArray).contains(textView.getText().toString())){ 

         }*/ 
        } 


        ArrayAdapter<ServicesModel> adapter = new ArrayAdapter<ServicesModel>(
          SearchActivity.this, 
          android.R.layout.simple_list_item_1, serviceArray); 
        textView.setAdapter(adapter); 
        //textView.setTextAppearance(getApplicationContext(), R.style.boldText); 
        textView.setOnItemClickListener(new OnItemClickListener() { 

         @Override 
         public void onItemClick(AdapterView<?> arg0, View arg1, 
           int arg2, long arg3) { 
          // TODO Auto-generated method stub 

          ServicesModel sm = (ServicesModel) arg0 
            .getItemAtPosition(arg2); 
          service_name = sm.name; 
          service_recog_id = sm.recognisationId; 

          textView.setText(""); 
          textView.append(sm.name); 
          textView.setVisibility(View.GONE); 
          textView.setVisibility(View.VISIBLE); 

         } 
        }); 

       } catch (JSONException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 

       // ==================================================================================== 
       ///// PEFORMING STUFF FOR BOTH KEYWORD AND LOCATION OVER HERE .. 
       // ==================================================================================== 

       try { 

        nmyJsonObject = new JSONObject(myJsonString); 
        nmyJsonArray = nmyJsonObject.getJSONArray("location"); 

        for (int i = 0; i < nmyJsonArray.length(); i++) { 

         JSONObject nobjJson = nmyJsonArray.getJSONObject(i); 
         city_name = nobjJson.getString("city_name"); 
         country_name = nobjJson.getString("country_name"); 

         LocationModel lm = new LocationModel(); 
         lm.City_Name = city_name; 
         lm.Country_Name = country_name; 
         locationArray.add(lm); 

        } 

        ArrayAdapter<LocationModel> adapter = new ArrayAdapter<LocationModel>(
          SearchActivity.this, 
          android.R.layout.simple_list_item_1, locationArray); 
        ltextView.setAdapter(adapter); 

        ltextView.setOnItemClickListener(new OnItemClickListener() { 

         @Override 
         public void onItemClick(AdapterView<?> arg0, View arg1, 
           int arg2, long arg3) { 
          // TODO Auto-generated method stub 
          LocationModel lm = (LocationModel) arg0 
            .getItemAtPosition(arg2); 
          city_name = lm.City_Name; 
          country_name = lm.Country_Name; 
         } 
        }); 

       } catch (JSONException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 

       pDialog.dismiss(); 

      } 

     } 

    } 
0

Попробуйте изменить строку ProgressDialog pd = new ProgressDialog(getBaseContext()); в вашем BackgroundTask класс до, ProgressDialog pd = new ProgressDialog(LogInActivity.this);

Смежные вопросы