【问题标题】:Update database phpMyAdmin更新数据库 phpMyAdmin
【发布时间】:2014-03-21 18:00:48
【问题描述】:

我有一个在我的应用程序上运行 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";

   }

谢谢。

【问题讨论】:

    标签: php android


    【解决方案1】:

    你可以做一个后台运行的服务,看看有没有更新

    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));
    

    【讨论】:

      猜你喜欢
      • 2019-01-11
      • 2015-09-10
      • 1970-01-01
      • 2017-03-04
      • 2019-06-01
      • 2020-07-12
      • 2018-06-17
      • 2011-02-05
      • 2012-12-07
      相关资源
      最近更新 更多