Just in case somebody is interested, everything works now. The key is to put 
the time into the faked location.

fakedLocation.setTime(System.currentTimeMillis());
locationManager.setTestProviderLocation(LocManager.MOCK_PROVIDER, 
fakedLocation);

I've also noticed that even though I was able to make a broadcast work with 
addProximityAlert, the intent in onReceive of the intent receiver is not the 
same as the one I created for the PendingIntent created with getBroadcast() 
passed to addProximityAlert. This might be an Android bug. If I do the same 
PendingIntent but use it to start a service with getService(), everything works 
fine.

I have one question left regarding service. If I let my service do 
addProximityAlert, but the service doesn't do anything but waiting for the 
alert. Can I be sure, that under normal circumstances the proximity alert will 
be kicked off, even after several days for instance, as long as I specify the 
expiration time as == -1?

----- Original Message ----- 
  From: Hendrik Greving 
  To: Android Developers 
  Sent: Sunday, November 14, 2010 8:05 PM
  Subject: addProximityAlert & lifecycle


  Hi I understand the documentation about activity and service lifecycle. 
Generally speaking, what's the approach if you want to have an application 
which gets unlimited proximity alerts, basically a service that doesn't die? 
I've tried startService with requestLocationUpdate etc. but after a while the 
service seems to get killed by the OS. That's basically question 1) :-) 

  Now to problem 2) I've tried to do addProximityAlert but it doesn't really 
seem to work. I am basically doing something like

  Intent updateIntent = new Intent(this, LocManIntentReceiver.class);
  updateIntent.addCategory(Intent.CATEGORY_INFO);
  updateIntent.setAction(Intent.ACTION_LOCALE_CHANGED);
  // Put the information into the Intent


  updateIntent.putExtra[..]
  // Create a pending broadcast intent for the proximity alertPendingIntent 
pendingIntent = PendingIntent.getBroadcast(this, -1, updateIntent, 
PendingIntent.FLAG_UPDATE_CURRENT);
  // Add a new proximity alert, update the old one
  locationManager.addProximityAlert((double)latitude/1E6, 
(double)longitude/1E6, (float)1, 1000000, pendingIntent);

  But if I set a breakpoint or do a Toast.makeText in the onReceive function of 
the BroadcastReceiver, I never get anything.

  Now to problem 3) :-) I've tried to set up a mock location provider by 
starting a "Timer" which periodically spits out a new location, and I set up a 
LocationListener. The timer does something like this

  LocationManager locationManager = 
(LocationManager)mContext.getSystemService(Context.LOCATION_SERVICE);
  locationManager.setTestProviderLocation(LocManager.MOCK_LOCMAN_PROVIDER, 
fakedLocation);

  I am passing the context in the constructor of the Timer object when 
instantiating it. The location listener in the main activity never received an 
update but the very first one. Any take on that?

  - Thanks!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to