Whats better, make a loop reading php in android or make a loop in php reading a database? -


i making application in android has read database hosted in server, question is, better make loop in android, reading php document or read once php document makes loop information database?

in android studio make loop sleep, , read php document. don't have code because haven't made it, here code connect php, imagine in loop:

    stringrequest conexion = new stringrequest(request.method.post,             constantes.url_nombreicono,             new response.listener<string>() {                 @override                 public void onresponse(string response) {                     if(response.charat(response.length() - 1) == '1'){                      }                     else {                         nombregrupo.settext(response);                     }                 }             },             new response.errorlistener() {                 @override                 public void onerrorresponse(volleyerror error) {                     toast("no se ha podido conectarse con la base de datos", "l");                 }             });     requestqueue requ = volley.newrequestqueue(this);     requ.add(conexion); 

and php code in case this:

<?php  $con = mysqli_connect('localhost','root','', 'jndatabase'); if (!$con) {     echo "|error"; } else{     $query = "select * log order id desc limit 1";     $resultado = $con->query($query);      if (!$resultado){         echo "|error";     }     else {         $row = $resultado->fetch_assoc();         if($row["realizada"] == 1){             echo $row["accion"]."|".$row["id"];         }                                            }  } 

?>

the other case, read php document once, php document makes loop, have code of loop in php:

<?php  ini_set('max_execution_time', 0);  while (true) {     $con = mysqli_connect('localhost','root','', 'jndatabase');     if (!$con) {         echo "|error";     }     else{         $query = "select * log order id desc limit 1";         $resultado = $con->query($query);          if (!$resultado){             echo "|error";         }         else {             $row = $resultado->fetch_assoc();             if($row["realizada"] == 1){                 echo $row["accion"]."|".$row["id"];             }                                                }      }     ob_flush();flush();sleep(1); } 

?>

so think better,having in mind android application , have take care battery.

pdt: know exists services firebase, want own server, know, try avoid giving information other companies

in android depends data received database. shouldn't make loop in php. when android device off-line? php should data database (maybe cache) , pass android device request.

if want show data database in ui , nothing else, can use loop or handler.postdelayed() api. nice if pause work when application closed or paused.

or if want work in background storing data in sqlite can use alarmmanager or jobscheduler api. there list of available tools.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -