Как отправить данные, которые отправлены из другой деятельности по назначению?

Перед перечислением элементов у меня есть функция приложения для создания новых данных, в которые входит уникальный идентификатор из другого действия. Уникальные данные — «sid». Я использовал PHP для подключения к базе данных phpmyadmin.

<?php

// array for JSON response
$response = array();

// check for required fields
if (isset($_POST['foodName']) && isset($_POST['foodPrice']) && isset($_POST['foodType']) && isset($_POST['sid']) {

$foodName = $_POST['foodName'];
$foodPrice = $_POST['foodPrice'];
$foodType = $_POST['foodType'];
$sid = $_POST['sid'];

// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

// mysql inserting a new row
$result = mysql_query("INSERT INTO food(foodName, foodPrice, foodType, sid) VALUES('$foodName', '$foodPrice', '$foodType', '$sid')");

// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Food successfully created.";

// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";

// echoing JSON response
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";

// echoing JSON response
echo json_encode($response);
}
?>

И это намерение получить данные из другой деятельности:

Intent i = getIntent();

// getting product id (sid) from intent
sid = i.getStringExtra(TAG_SID);

Наконец, у меня есть это в классе, когда он выполняется:

protected String doInBackground(String... args) {

// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("foodName", getFoodName));
params.add(new BasicNameValuePair("foodPrice", getFoodPrice));
params.add(new BasicNameValuePair("foodType", getFoodType));
params.add(new BasicNameValuePair("sid", sid));

Есть ли что-то, что я где-то сделал не так? У меня на столе тоже есть этот «сид».

0

Решение

Вы должны сделать следующее
в первом занятии

Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("sid", VALUE);
startActivity(intent);

во второй деятельности

Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("sid");
}
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector