2016-09-29 9 views
-1

バックエンドサーバーに接続することでページを更新するタイミングバックグラウンドサービスは、ネットワークの再開、リフレッシュWebView、表示を復元する場合、検出を継続します。が、私はこの機能を実現したい

2)ネットワークがOKの場合、バックグラウンドサーバに新しいURLが指定されている場合はバックグラウンドサービスが検出され続け、現在のページがリフレッシュされます。

答えて

0

AlarmManagerとPendingIntentとともにブロードキャスト受信機を使用できます。あなたの希望の期間、アラームの繰り返しを設定し、その期間に保留中のインテントを発生させます。

public void scheduleAlarmForURLAutoUpdate() { 
     Long time = new GregorianCalendar().getTimeInMillis()+1000 * 60 * 60 * 24;// current time + 24 Hrs 
     Intent intent = new Intent(this, AlarmReceiver.class); 
     PendingIntent intentAlarm = PendingIntent.getBroadcast(this, 0, intent, 0); 
     AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); 
     alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, 1000 * 60 * 60 * 24, intentAlarm);// 24 Hrs 
     //Toast.makeText(this, "Alarm Scheduled for 24 Hrs", Toast.LENGTH_LONG).show(); 
    } 

AlarmReceiverクラス

public class AlarmReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     updateURL(context);//Method to update the URL from the server and then refresh your WebView activity 


} 
+0

を拡張し、私はまだ解決できないあなたのanswer.Butために本当に感謝していますこの質問。サーバーから新しいURLを取得した場合、どのようにWebViewを更新できますか?私は使う?ありがとう。 – JiangDelin

0

パブリッククラスAlarmReceiverはBroadcastReceiver {

@Override 
public void onReceive(Context context, Intent intent) 
{ 
    Intent i = new Intent(context, AutoUpdateService.class); 
    context.startService(i); 
} 

}

関連する問題