私のアクティビティでは、サーバーをポーリングして更新を取得し続け、そのデータをデータベースに保存し、そこから表示します。私の質問は、更新を取得したときに、更新せずにそのアクティビティ画面に表示する方法です (FACEBOOK のように) 助けてください。
ログイン アクティビティでは、この関数を呼び出します。
public void PollingViaAlarm() {
try {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
Intent intent = new Intent(getApplicationContext(),PollingAlarm.class);
intent.putExtra("title", "Polling Via Server");
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + 5 * 60 * 1000, 5 * 60 * 1000,pendingIntent);
} catch (Exception e) {
}}
PollingAlarm クラスでは、関数を呼び出してサーバーをポーリングします。
cnstnt.getUserMessagesPollingAlarm(patient_id,username,password, "123");
cntxt.startService(new Intent(cntxt, NotificationService.class));
通知クラスでは、
package com.vcare.cnstnt;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class NotificationService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
SharedPref shrd = new SharedPref(getApplicationContext());
Intent i = new Intent("android.intent.action.MAIN").putExtra(
"msg_count", "" + shrd.getMsgCount());
Log.e("msg_count in notification service", "" + shrd.getMsgCount());
if (shrd.getMsgCount() > 0) {
Log.e("starting broadcasting","");
this.sendBroadcast(i);
this.stopSelf();
}
}
}
可能であれば、私がやろうとしていることをチェックしていただけますか。Facebookのような通知を実現する必要があります。