在我的应用程序中,我有一个活动和服务...该服务将广播从GPS数据收集的消息...活动应该接收广播消息并更新UI ...
我的代码
public class LocationPollerDemo extends Activity {
private static final int PERIOD = 10000; // 30 minutes
private PendingIntent pi = null;
private AlarmManager mgr = null;
private double lati;
private double longi;
private ServiceReceiver serviceReceiver;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mgr = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent i = new Intent(this, LocationPoller.class);
i.putExtra(LocationPoller.EXTRA_INTENT, new Intent(this, ServiceReceiver.class));
i.putExtra(LocationPoller.EXTRA_PROVIDER, LocationManager.GPS_PROVIDER);
pi = PendingIntent.getBroadcast(this, 0, i, 0);
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), PERIOD, pi);
DebugLog.logTrace("On Create Demo");
Toast.makeText(this, "Location polling every 30 …Run Code Online (Sandbox Code Playgroud) android ×1