Browse Source

database

pull/1/head
Yiğit Çolakoğlu 7 years ago
parent
commit
5f5327a1e1
2 changed files with 16 additions and 14 deletions
  1. +5
    -9
      FoodCloud/app/src/main/java/gq/yigit/foodcloud/PHPComm.java
  2. +11
    -5
      FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java

+ 5
- 9
FoodCloud/app/src/main/java/gq/yigit/foodcloud/PHPComm.java View File

@ -18,9 +18,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
/**
* Created by ProgrammingKnowledge on 1/5/2016.
*/
public class PHPComm extends AsyncTask<String,Void,String> {
private static final String TAG = "MainActivity";
Context context;
@ -28,13 +25,14 @@ public class PHPComm extends AsyncTask<String,Void,String> {
PHPComm (Context ctx) {
context = ctx;
}
static public String return_json;
static String json_return;
@Override
protected String doInBackground(String... params) {
String type = params[0];
String login_url = "http://192.168.1.21/database/communication/comm.php";
if(type.equals("get")) {
try {
Log.d(TAG,"received get");
String id = params[1];
String value = params[2];
URL url = new URL(login_url);
@ -79,15 +77,13 @@ public class PHPComm extends AsyncTask<String,Void,String> {
@Override
protected void onPostExecute(String result) {
alertDialog.setMessage(result);
Log.d(TAG, "AlertBoxSet" + result);
setJson(result);
Log.d(TAG, "AlertBoxSet " + result);
json_return = result;
alertDialog.show();
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
static private void setJson(String json){
return_json = json;
}
}

+ 11
- 5
FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java View File

@ -84,17 +84,23 @@ public class ProductInfo extends AppCompatActivity implements OnClickListener {
Bundle extras = getIntent().getExtras();
if (extras != null) {
prod_loc = extras.getString("key");
//The key argument here must match that used in the other activity
//The key argument here must match that used in the other activitylgo
}
// This method is called once with the initial value and again
// whenever data at this location is updated.
PHPComm comm = new PHPComm(this);
comm.execute("get", "1", "Products");
try {
json_str = PHPComm.return_json;
Log.d(TAG,"get json str" + json_str);
JSONObject jsonObj = new JSONObject(json_str);
}catch (JSONException e) {
json_str = comm.json_return;
while(json_str == null){
json_str = comm.json_return;
continue;
}
Log.d(TAG,"This is a pointer");
//Log.d(TAG,"get json str" + json_str);
//JSONObject jsonObj = new JSONObject(json_str);
}catch (NullPointerException e) {
Log.d(TAG, "An error occured with the json!");
}
/*


Loading…
Cancel
Save