Android Studio – NameValuePair and HttpParams is deprecated

Issue

I am new to Android development and I am have some deprecated issues. In Android Studio, it is stating that the NameValuePair and HttpParams is deprecated.

ArrayList<NameValuePair> dataToSend = new ArrayList<>();
        dataToSend.add(new BasicNameValuePair("fname", user.fname));
        dataToSend.add(new BasicNameValuePair("lname", user.lname));
        dataToSend.add(new BasicNameValuePair("email", user.email));
        dataToSend.add(new BasicNameValuePair("password", user.password)); 

HttpParams httpRequestParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpRequestParams, CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpRequestParams, CONNECTION_TIMEOUT);

        HttpClient client = new DefaultHttpClient(httpRequestParams);
        HttpPost post = new HttpPost(SERVER_ADDRESS + "register");

When searching for answers, I am getting sent to use openconnection(), but I don’t see how that applies to code above.

Solution

Did you try to use ContentValues ?

From this snippet of code I am not sure if it would help you.

ContentValues values=new ContentValues();

  values.put("fname",user.fname);
  values.put("lname", user.lname);
  values.put("email",user.email);
  values.put("password",user.password);

Answered By – TheLibrarian

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *