更新数据库phpMyAdmin

时间:2014-03-21 18:00:49

标签: php android

我有一个数据库,我在我的应用程序上运行phpmyadmin。一切正常,但我想知道是否有办法检查数据库的最新更新。 这是我的java代码:

try {
   String s = "";
   JSONArray jArray = new JSONArray(result);

   for(int i=0; i<jArray.length();i++){
       JSONObject json = jArray.getJSONObject(i);
       locale[i]=json.getString("Locale");
       lunedi[i]=json.getString("Lunedi");
       martedi[i]=json.getString("Martedi");
       mercoledi[i]=json.getString("Mercoledi");
       giovedi[i]=json.getString("Giovedi");
       venerdi[i]=json.getString("Venerdi");
       sabato[i]=json.getString("Sabato");
       domenica[i]=json.getString("Domenica");
       info1[i]=json.getString("info1");
       info2[i]=json.getString("info2");
       info3[i]=json.getString("info3");
       info4[i]=json.getString("info4");
       info5[i]=json.getString("info5");
       info6[i]=json.getString("info6");
       info7[i]=json.getString("info7");
       id[i]=json.getString("id");

       s = s + 

               "Id : "+json.getInt("id")+"\n\n";

   }

感谢。

1 个答案:

答案 0 :(得分:0)

您可以制作在backGround中运行的服务并检查是否有更新

public class NotifService extends Service {

public NotifService() {
}


public void onCreate() {
    //when the service created
    super.onCreate();

}

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onStart(Intent intent,int startId) {
    super.onStart(intent,startId);
    isRunning = true;
    handler = new Handler(){

        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            super.handleMessage(msg);

           //**** do your woek here : in your case connect to your database and see  
         if there is some new tuples **************/

        }
        }

    };


   //every 30 min the service will call
    new Thread(new Runnable(){
        public void run() {
        // TODO Auto-generated method stub
        while(isRunning)
        {
           try {
            Thread.sleep(1800000);//30min =1800000
            handler.sendEmptyMessage(0);

           } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
           } 

        }

                        }
    }).start();
}

@Override
public void onDestroy() {
    isRunning = false;

    super.onDestroy();
}


}

并启动您编写的服务

 startService(new Intent(this, NotifService.class));

关闭服务写入

 stopService(new Intent(this, NotifService.class));