@Override
    protected void onPostExecute(JSONObject json) {
      try {
        if (json.getBoolean("success")) {
          // everything is ok
          SharedPreferences.Editor editor = mPreferences.edit();
          // save the returned auth_token into
          // the SharedPreferences
          editor.putString("AuthToken", json.getJSONObject("data").getString("auth_token"));
          editor.commit();

          // launch the HomeActivity and close this one
          Intent intent = new Intent(getApplicationContext(), MainActivity.class);
          startActivity(intent);
          finish();
        }
        Toast.makeText(context, json.getString("info"), Toast.LENGTH_LONG).show();
      } catch (Exception e) {
        // something went wrong: show a Toast
        // with the exception message
        Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
      } finally {
        super.onPostExecute(json);
      }
    }
示例#2
0
    @Override
    protected void onPostExecute(JSONObject json) {
      try {
        if (json.getBoolean("success")) {
          SharedPreferences.Editor editor = mPreferences.edit();
          editor.putString("AuthToken", json.getJSONObject("data").getString("auth_token"));
          editor.commit();

          Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
          startActivity(intent);
          finish();
        }
        Toast.makeText(context, json.getString("info"), Toast.LENGTH_LONG).show();
      } catch (Exception e) {
        Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
      } finally {
        super.onPostExecute(json);
      }
    }