课程:时间
public class Time {
public int LPassIN;
public int LPassOUT;
int secondPassed = 0;
Timer mytime = new Timer();
String PPassIN = Integer.toString(LPassIN);
String PPassOUT = Integer.toString(LPassOUT);
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
} catch (JSONException e) {
e.printStackTrace();
}
}
};
ServerI serv = new ServerI(PPassIN,PPassOUT,responseListener);
RequestQueue queue = Volley.newRequestQueue(Time.this);
TimerTask mytask = new TimerTask() {
public void run() {
secondPassed++;
if (secondPassed == 11) {
secondPassed = 0;
Convertion callConvertion = new Convertion();
try {
callConvertion.cnvrt();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int donecnvrtin = callConvertion.donecnvrtin();
int donecnvrtout = callConvertion.donecnvrtout();
if (LPassIN != donecnvrtin) {
LPassIN = donecnvrtin;
queue.add(serv);
System.out.println(LPassIN);
}
if (LPassOUT != donecnvrtout) {
LPassOUT = donecnvrtout;
queue.add(serv);
System.out.println(LPassOUT);
}
} else {
System.out.println("Second : " + secondPassed);
}
}
};
类:ServerI
public class ServerI extends StringRequest {
private static final String UPLOAD_URL="http://userfb.esy.es/serverInteraction.php";
public Map<String,String> params;
public ServerI(String PPassIN,String PPassOUT,Response.Listener<String> listener){
super(Method.POST,UPLOAD_URL,listener,null);
params = new HashMap<>();
params.put("PPassIN",PPassIN);
params.put("PPassOUT",PPassOUT);
}
@Override
public Map<String,String> getParams(){
return params;
}
}
PHP代码
<?php
$con = mysqli_connect("\", "\", "\", "\");
$PPassIN = $_POST["PPassIN"];
$PPassOUT = $_POST["PPassOUT"];
$statement = mysqli_prepare($con,"INSERT INTO Count(PassIN,PassOUT) VALUES (?,?)");
mysqli_stmt_bind_param($statement,"ss", $PPassIN, $PPassOUT):
mysqli_stmt_execute($statement);
$response = array();
$response ["success"] = true;
echo json_encode($response);
?>
请帮助我,我试图每隔10秒将数据发布到服务器/数据库MySQL,数据来自其他类
这是后台服务
那怎么办呢?这是我的概念错了吗? 启动时我的服务崩溃