我的应用程序是在模拟器中运行但不是在phone.its登录到我的下一个活动后不会运行

时间:2015-03-16 07:16:20

标签: android

  
    

这是log cat

 in this succes full value of json
  
03-16 11:52:33.031: E/IMGSRV(8587): :0: PVRDRMOpen: TP3, ret = 46
03-16 11:52:33.031: E/IMGSRV(8587): :0: PVRDRMOpen: TP3, ret = 49
03-16 11:52:33.031: E/IMGSRV(8587): :0: PVRDRMOpen: TP3, ret = 50
03-16 11:52:33.031: E/IMGSRV(8587): :0: PVRDRMOpen: TP3, ret = 50
03-16 11:52:33.031: E/IMGSRV(8587): :0: PVRDRMOpen: TP3, ret = 50
03-16 11:52:33.051: E/IMGSRV(8587): :0: PVRDRMOpen: TP3, ret = 52
03-16 11:52:33.351: E/RenderScript(8587): Skipping override driver 'libPVRRS.so' and loading default CPU driver 'libRSDriver.so'.
03-16 11:53:05.781: E/http://192.162.14.148/clock/webservice/login.php(8587): http://192.168.1.148/clock/webservice/login.php
03-16 11:53:05.781: E/request!(8587): starting
03-16 11:53:07.101: E/json response(8587): {"message":"Login successful!","first_name":"Himanshu","last_name":"Negi","user_id":"29939","type":2,"success":"1","password":"test","user_id1":"1001031"}
  
    

这是我的清单文件

  
<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="info.androidhive.slidingmenu"
        android:versionCode="1"
        android:versionName="1.0" >

        <uses-sdk
            android:minSdkVersion="11"
            android:targetSdkVersion="21" />
        <!-- Internet Permissions -->
        <uses-permission android:name="android.permission.INTERNET" />

        <!-- Network State Permissions -->
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.clockerp.login.LoginActivity"
                android:theme="@android:style/Theme.NoTitleBar" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name="com.clockerp.Student.MainActivity"
                android:label="@string/app_name" >
            </activity>
            <activity
                android:name="com.clockerp.Employee.EmployeeMainActivity"
                android:label="@string/title_activity_employee_main" >
            </activity>

               </application>

    </manifest>
  

现在这是我的loginpage.java

     

在此问题是登录成功但新活动不是呼叫..仅保留在登录页面上   请检查doPost()方法

package com.clockerp.login;

import java.util.ArrayList;
import java.util.List;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;



import com.clockerp.Employee.EmployeeMainActivity;
import com.clockerp.Student.MainActivity;
import com.clockerp.connection.*;
import com.clockerp.db.LoginDAO;

import info.androidhive.slidingmenu.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity  extends Activity {

    Button b;
    EditText unamefield;
    EditText pswdfield;
    EditText domainfield;
    LoginDAO LD;
     String username;
     String password;
     String domain;
     JSONObject json;

     int success = 0;
     String type = "";

    //ImageButton eye;

    public SharedPreferences pref;
    public Editor editor;

    ConnectionDetector cd ;

     // Progress Dialog
    private ProgressDialog pDialog = null;

    // JSON parser class
    JSONParser jsonParser = new JSONParser();

    // URL to get Login JSON
    private static String url = "http://mainerp.clockerp.com/webservice/login.php?";

 // JSON Node names
    private static final String TAG_SUCCESS = "success";




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_login);



        b = (Button) findViewById(R.id.signin);

        unamefield = (EditText)findViewById(R.id.username);
        pswdfield = (EditText)findViewById(R.id.password);
        domainfield = (EditText)findViewById(R.id.domain);



        pref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE); 
        editor = pref.edit();

        cd = new ConnectionDetector(getApplicationContext());
        Boolean isInternetPresent = cd.isConnectingToInternet();

        if(isInternetPresent){
         if(pref.getString("username", null) != null  ){

                Intent intent = new Intent(LoginActivity.this,MainActivity.class);
                intent.putExtra("domain",pref.getString("domain", null) );
                 intent.putExtra("username", pref.getString("username", null));
                 intent.putExtra("password", pref.getString("password", null));
                 intent.putExtra("type", pref.getInt("type",2));
                startActivity(intent);
                finish();

             }
        }
        else{

            Toast.makeText(getApplicationContext(), "Please check Internet connection and try again.", Toast.LENGTH_LONG).show();
            finish();

        }


        b.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                 Boolean isInternetPresent = cd.isConnectingToInternet();
                 if(isInternetPresent){
                     new AttemptLogin().execute();
                 }
                 else{
                     Toast.makeText(getApplicationContext(), "Please check Internet connection and try again.", Toast.LENGTH_LONG).show();
                 }


            }
        });

    }



    @SuppressWarnings("rawtypes")
    class AttemptLogin extends AsyncTask<String, String, String> {

        /**
        * Before starting background thread Show Progress Dialog
        * */
       boolean failure = false;

       @Override
       protected void onPreExecute() {
           super.onPreExecute();
           pDialog = new ProgressDialog(LoginActivity.this);
           pDialog.setMessage("Checking Credentials...");
         //  pDialog.setIndeterminate(false);
          pDialog.setCancelable(true);
           pDialog.show();
       }

       @SuppressWarnings("unchecked")
    @Override
       protected String doInBackground(String... args) {
           // TODO Auto-generated method stub
            // Check for success tag

                username = unamefield.getText().toString();
                password = pswdfield.getText().toString();
                domain = domainfield.getText().toString();

           if(username.matches("")){
               runOnUiThread(new Runnable() {
                   public void run() {
                      // Toast.makeText(MainActivity.this, "user name cannot be empty", Toast.LENGTH_LONG).show(); 
                       showalertemptyusername();

                   }});

           }
           else if(password.matches("")){

               runOnUiThread(new Runnable() {
                   public void run() {
                       //Toast.makeText(getApplicationContext(), "Password cannot be empty", Toast.LENGTH_LONG).show();  
                       showalertemptypassword();
                   }});
           }
           else if(domain.matches("")){
               //
               runOnUiThread(new Runnable() {
                   public void run() {
                      // Toast.makeText(getApplicationContext(), "Domain cannot be empty", Toast.LENGTH_LONG).show(); 
                       showalertemptydomain();
                   }});
           }


           else{

              // showAlert();
               try {

                  String finalurl = null;
                   // Building Parameters
                   List params = new ArrayList();
                   params.add(new BasicNameValuePair("domain", domain));
                   params.add(new BasicNameValuePair("username", username));
                   params.add(new BasicNameValuePair("password", password));

                   String last = null;
                   if(domain.contains("clockerp.com")){
                       last = domain.substring(0, domain.length()-13); 
                       finalurl = url+"domain="+last;
                       Log.e(finalurl,finalurl);
                   }
                   else{
                       finalurl = "http://"+domain+"/webservice/login.php" ;
                       Log.e(finalurl,finalurl);
                   }


                   Log.e("request!", "starting");
                   // getting product details by making HTTP request
                 json = jsonParser.makeHttpRequest(
                          finalurl, "POST", params);
                //   params.add(new BasicNameValuePair("domain", finalurl));
                       if(json!=null){
                           success = json.getInt(TAG_SUCCESS);

                           type = json.getString("type");
                           Log.e("json response",json.toString());
                       }
                       else{
                           Log.e("json response","Empty json");
                           showAlertdomainnonexistance();

                       }




//                         else{
//                           
//                           runOnUiThread(new Runnable() {
//                                 public void run() {
//                                  // showalertwrongcredentials();
//                                     Toast.makeText(getApplicationContext(), "Login Failed", Toast.LENGTH_LONG).show();  
//                                 }});
//                           
//                         }




               } catch (JSONException e) {
                   e.printStackTrace();
               }

           }

          return null;  
       }
       /**
        * After completing background task Dismiss the progress dialog
        * **/
       protected void onPostExecute(String file_url) {
           // dismiss the dialog once product deleted




             if (success == 1&& type=="2") {
               Log.e("Login done!", json.toString());
               editor.putString("type", type);

               editor.putString("username", username);
               editor.putString("password", password);
               editor.putString("domain", domain);

               editor.commit();


               Intent intent = new Intent(LoginActivity.this,MainActivity.class);
               intent.putExtra("domain", domain);
               intent.putExtra("username", username);
               intent.putExtra("password", password);
               intent.putExtra("type", type);
               startActivity(intent);
               finish();




           }else if (success == 1 && type=="3") {
             Log.e("Login done!", json.toString());

             editor.putString("username", username);
             editor.putString("password", password);
             editor.putString("domain", domain);
             editor.putString("type", type);
             editor.commit();

             Intent intent = new Intent(LoginActivity.this,EmployeeMainActivity.class);
             intent.putExtra("domain", domain);
             intent.putExtra("username", username);
             intent.putExtra("password", password);
             intent.putExtra("type", type);
             startActivity(intent);
             finish();



         }else if(success == 0){
               runOnUiThread(new Runnable() {
                   public void run() {
                    // showalertwrongcredentials();
                       Toast.makeText(getApplicationContext(), "Login Failed", Toast.LENGTH_LONG).show();  
                   }});

           }            



           pDialog.dismiss();


       }      
   }

    public void showAlertdomainnonexistance(){
       LoginActivity.this.runOnUiThread(new Runnable() {
            @SuppressWarnings("deprecation")
            public void run() {

                AlertDialog alertDialog = new AlertDialog.Builder(
                        LoginActivity.this).create();

        // Setting Dialog Title
        alertDialog.setTitle("Clock");

        // Setting Dialog Message
        alertDialog.setMessage("Sorry this domain does not exist");

        // Setting Icon to Dialog
        alertDialog.setIcon(R.drawable.tick);

        // Setting OK Button
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();

                }
        });

        // Showing Alert Message
        alertDialog.show();
            }
        });
    } 

    public void showalertemptyusername(){
        LoginActivity.this.runOnUiThread(new Runnable() {
            @SuppressWarnings("deprecation")
            public void run() {

                AlertDialog alertDialog = new AlertDialog.Builder(
                       LoginActivity.this).create();

        // Setting Dialog Title
        alertDialog.setTitle("Clock");

        // Setting Dialog Message
        alertDialog.setMessage("Username field cannot be empty");

        // Setting Icon to Dialog
        alertDialog.setIcon(R.drawable.tick);

        // Setting OK Button
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();

                }
        });

        // Showing Alert Message
        alertDialog.show();
            }
        });
    }

   public void showalertemptypassword(){

       LoginActivity.this.runOnUiThread(new Runnable() {
           @SuppressWarnings("deprecation")
            public void run() {

            AlertDialog alertDialog = new AlertDialog.Builder(
                      LoginActivity.this).create();

       // Setting Dialog Title
       alertDialog.setTitle("Clock");

       // Setting Dialog Message
       alertDialog.setMessage("Password field cannot be empty");

       // Setting Icon to Dialog
       alertDialog.setIcon(R.drawable.tick);

       // Setting OK Button
       alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int which) {
               dialog.cancel();

               }
       });

       // Showing Alert Message
       alertDialog.show();
           }
       });
   }

  public void  showalertemptydomain(){

     LoginActivity.this.runOnUiThread(new Runnable() {
          @SuppressWarnings("deprecation")
            public void run() {

            AlertDialog alertDialog = new AlertDialog.Builder(
                      LoginActivity.this).create();

      // Setting Dialog Title
      alertDialog.setTitle("Clock");

      // Setting Dialog Message
      alertDialog.setMessage("Domain field cannot be empty");

      // Setting Icon to Dialog
      alertDialog.setIcon(R.drawable.tick);

      // Setting OK Button
      alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
              dialog.cancel();

              }
      });

      // Showing Alert Message
      alertDialog.show();
          }
      });
  }

  public void showalertimproperformat(){

     LoginActivity.this.runOnUiThread(new Runnable() {
          @SuppressWarnings("deprecation")
            public void run() {

            AlertDialog alertDialog = new AlertDialog.Builder(
                     LoginActivity.this).create();

      // Setting Dialog Title
      alertDialog.setTitle("Clock");

      // Setting Dialog Message
      alertDialog.setMessage("Domain format is improper.Please check");

      // Setting Icon to Dialog
      alertDialog.setIcon(R.drawable.tick);

      // Setting OK Button
      alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
              dialog.cancel();

              }
      });

      // Showing Alert Message
      alertDialog.show();
          }
      });  

  }

  public void showalertwrongcredentials(){

      LoginActivity.this.runOnUiThread(new Runnable() {
          @SuppressWarnings("deprecation")
            public void run() {

            AlertDialog alertDialog = new AlertDialog.Builder(
                      LoginActivity.this).create();

      // Setting Dialog Title
      alertDialog.setTitle("Clock");

      // Setting Dialog Message
      alertDialog.setMessage("Please check login credentials");

      // Setting Icon to Dialog
      alertDialog.setIcon(R.drawable.tick);

      // Setting OK Button
      alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
              dialog.cancel();

              }
      });

      // Showing Alert Message
      alertDialog.show();
          }
      }); 

  }




}

1 个答案:

答案 0 :(得分:0)

根据您的JSON回复,

{
 "message":"Login successful!","first_name":"Himanshu",
 "last_name":"Negi","user_id":"29939",
 "type":2,"success":"1","password":"test","user_id1":"1001031"
}

类型看起来像一个int字段,成功一个字符串字段。 尝试更改

if (success == 1&& type=="2") {

if (success.equals("1") && type == 2) {