user1949387 user1949387 - 6 months ago 20
Java Question

NameValuePair deprecated for openConnection

I been following online tutorials on how to insert data into a database from an android app and have everything working except this small part

List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));


NameValuePair and BasicNameValuePair have been deprecated in favor of
openConnection()
. How can I create a new-value association with that? http://developer.android.com/reference/java/net/URL.html#openConnection()

Does anyone know how I can create name value pairs with openConnection? I been searching everywhere.

Answer

You can use contentValues for example

ContentValues values=new ContentValues();
values.put("username",name);
values.put("password",password);
database.insert(Table_name,null,values);