-1

私はいくつかの奇妙な問題があります。意図がの共有環境設定コードの後に動作していません。私がと書いている場合の前に同じの意図を書いています。共有環境設定コード、それは働いています。以下は、以下奇妙な:共有環境設定コードの後に​​意図していない意図

チェックなFetchData()メソッド ...

Login_Activity

public class Login_Activity extends AppCompatActivity implements View.OnClickListener { 

    // Widgets 
    private Spinner spnr_login_type; 
    private EditText edt_login_id, edt_pwd; 
    private Button btn_login, btn_regi; 
    private ProgressDialog progressDialog; 

    // Variables 
    private String url = "login.php"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_login); 

     // Checking User Already Login OR Not 
     if (Preferences.getPreferences(getApplicationContext()).contains(Preferences.KEY_USER_NAME)) { 
      Intent myIntent = new Intent(Login_Activity.this, Home_Activity.class); 
      startActivity(myIntent); 
      finish(); 
     } 
     find_view_by_id(); 
     registerClickListeners(); 
     progressDialog = new ProgressDialog(this); 
     progressDialog.setIndeterminate(true); 
    } 

    private void find_view_by_id() { 
     spnr_login_type = (Spinner) findViewById(R.id.spnr_login_type); 
     edt_login_id = (EditText) findViewById(R.id.edt_login_id); 
     edt_pwd = (EditText) findViewById(R.id.edt_pwd); 
     btn_login = (Button) findViewById(R.id.btn_login); 
     btn_regi = (Button) findViewById(R.id.btn_regi); 
    } 

    private void registerClickListeners() { 
     btn_login.setOnClickListener(this); 
     btn_regi.setOnClickListener(this); 
    } 

    @Override 
    public void onClick(View view) { 
     switch (view.getId()) { 
      case R.id.btn_login: 
       if (Commom_Methods.isNetworkAvailable(getApplicationContext())) { 
        fetchData(); 
       } else { 
        Toast.makeText(Login_Activity.this, "Please, Coonect to internet!!", Toast.LENGTH_SHORT).show(); 
       } 
       break; 
      case R.id.btn_regi: 
       Intent myIntent = new Intent(Login_Activity.this, Regi_Activity.class); 
       startActivity(myIntent); 
       break; 
     } 
    } 

    private void fetchData() { 
     StringRequest stringReq = new StringRequest(Request.Method.POST, Constants.base_url + url, new Response.Listener<String>() { 
      @Override 
      public void onResponse(String response) { 
       Log.e("Resqq:", response); 
       progressDialog.dismiss(); 
       if (response != null) { 
        try { 
         JSONObject jo = new JSONObject(response); 
         if (jo.has("success")) { 
          JSONObject joObj = jo.getJSONObject("user"); 

          // Storing To Shared Preferences 
          Preferences.writeString(getApplicationContext(), 
            Preferences.KEY_SL_ID, joObj.getString("sl_id")); 
          Preferences.writeString(getApplicationContext(), 
            Preferences.KEY_TUTION_CENTER_SL, joObj.getString("tution_center_sl")); 
          Preferences.writeString(getApplicationContext(), 
            Preferences.KEY_BATCH_SL, joObj.getString("batch_sl")); 
          Preferences.writeString(getApplicationContext(), 
            Preferences.KEY_BATCH_GRUP_SL, joObj.getString("batch_grup_sl")); 
          Preferences.writeString(getApplicationContext(), 
            Preferences.KEY_CO_SL, joObj.getString("co_sl")); 
          Preferences.writeString(getApplicationContext(), 
            Preferences.KEY_DRANGE_SL, joObj.getString("drange_sl")); 

          Preferences.writeString(getApplicationContext(), 
            Preferences.KEY_REG_NO, joObj.getString("reg_no")); 
          Preferences.writeString(getApplicationContext(), 
            Preferences.KEY_USER_NAME, joObj.getString("name")); 
          Preferences.writeString(getApplicationContext(), 
            Preferences.KEY_USER_EMAIL, joObj.getString("email")); 
          Preferences.writeString(getApplicationContext(), 
            Preferences.KEY_USER_MOB, joObj.getString("mobile_no")); 

          Intent myIntent = new Intent(Login_Activity.this, Home_Activity.class); 
          startActivity(myIntent); 
          finish(); 

         } else { 
          Toast.makeText(getApplicationContext(), jo.getString("error_msg"), Toast.LENGTH_LONG).show(); 
         } 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } else { 
        Toast.makeText(Login_Activity.this, "Server error! Server sent empty data!! Try again later.", Toast.LENGTH_LONG).show(); 
       } 
      } 
     }, new Response.ErrorListener() { 
      @Override 
      public void onErrorResponse(VolleyError error) { 
       progressDialog.dismiss(); 
       Toast.makeText(getApplicationContext(), "Error:" + error.getMessage(), Toast.LENGTH_LONG).show(); 
      } 
     }) { 
      @Override 
      protected Map<String, String> getParams() { 
       Map<String, String> params = new HashMap<String, String>(); 
       params.put("type", spnr_login_type.getSelectedItem().toString().toLowerCase()); 
       params.put("reg_no", edt_login_id.getText().toString()); 
       params.put("password", edt_pwd.getText().toString()); 
       return params; 
      } 
     }; 
     RequestQueue queue = Volley.newRequestQueue(this); 
     queue.add(stringReq); 

     progressDialog = new ProgressDialog(this); 
     progressDialog.setMessage("Fetching your details!"); 
     progressDialog.show(); 
     //progressDialog.show(new ContextThemeWrapper(this, R.style.DialogCustom), "Fetching your details!", ""); 
    } 
} 

{ 
    "success": true, 
    "user": { 
    "sl_id": "1", 
    "reg_no": "21711101", 
    "name": "Akash Bharadwaj N", 
    "photo": "", 
    "email": "", 
    "type": "student" 
    }, 
    "api_key": "APIkey Here" 
} 
+0

define *共有設定コード* – Selvin

+0

が多すぎるとインテントが機能しません。はっきりしていない、どのラインではうまくいかない。 –

+1

あなたのlogcatはJSON例外を出力しましたか?ここにあなたのログを追加することを検討してください –

答えて

0
if (Preferences.getPreferences(getApplicationContext()).contains(Preferences.KEY_USER_NAME)) 
...私の回答です...私のコードです

はfalseを返す必要があります ブール値を確認してください

+0

もし私がこれらの行にコメントをつけるのであれば、** ISSUE **はそのままです。@jitesh mohite –

+0

shareprefereceコードは約 –

+0

です。** //共有設定に保存**この行。@ jitesh mohite –

関連する問題