Shedule UI update
<p>My app contains an activity which UI has to be updated due to server show schedule. What is the best approach for updating UI in this situation. </p>

<p>So far, I've come up with AlarmManager and Service but I'm not sure it's a good practice. Any other suggestions ? I've seen some relevant methods in Handler but I'm not how to use them regarding the uptime parameter.</p>

<p>Alarm</p>

<pre><code>    Intent intent = new Intent(getActivity(), OnAirUpdateAlarmReceiver.class);
    PendingIntent sender = PendingIntent.getBroadcast(getActivity(),
            0, intent, 0);

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, 10);

    AlarmManager am = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
</code></pre>

<p>Receiver (checks whether the running activity is one the needs to updated)</p>

<pre><code>@Override
public void onReceive(Context context, Intent intent) {
    ActivityManager am = (ActivityManager) context
            .getSystemService(Activity.ACTIVITY_SERVICE);
    List&lt;ActivityManager.RunningTaskInfo&gt; taskInfo = am.getRunningTasks(1);
    String name = taskInfo.get(0).topActivity.getShortClassName();
    if (name.equals(".activity.handset.HandsetMainActivity")) {
        Intent notificationIntent = new Intent(context,
                HandsetMainActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        notificationIntent.putExtra(
                context.getResources().getString(
                        R.string.extras_main_activity_on_new_intent),
                HandsetMainActivity.UPDATE_PLAYER_FRAGMENT_UI);
        context.startActivity(notificationIntent);
    }
}
</code></pre>

<p>And if it is - requests fragments UI update. Again not sure if this is the best solution.</p>

<p>Thanks for your suggestions.</p>
