2012-05-02 18 views
0

私はデータベースに接続するAndroidアプリケーションを持っています。私はバックグラウンドスレッドを書いて、データベースからのデータを継続的に更新したいと思います。私はそれをどうすればいいのでしょうか?例えば、私たちが新しいメッセージを受け取ったら、スカイプで通知の権利を得るでしょう。私がしたいと思うように...身体が私を助けることができますか?アンドロイドでサービス+通知を受け取ることができません

+1

あなたが試したことは?あなたのコードはどこですか? –

答えて

0

これは次のように行うことができます。あなたのActivityには、次のものが含まれている必要があります

//the method which changes the data in the database 
changeDataBD(params) { 
    new Thread(new Runnable() { 
     changingDataDB(params); 
    }).start(); 
} 

//create an handler 
private final Handler myHandler = new Handler(); 

private void changingDataDB(params) { 
    //.... changing of data in DB according to passed params 

    //update the UI using the handler and the runnable 
    myHandler.post(updateRunnable); 

} 

final Runnable updateRunnable = new Runnable() { 
    public void run() { 
     //call the activity method that updates the UI 
     updateUIandShowNotification(); 
    } 
}; 

private void updateUIandShowNotification() { 
     // ... update the data on UI 
     // ... show a notification 
} 

また、データベースの変化を監視するリスナーを作成することができます。そして、このスレッドを開始する必要があります。

関連する問題