> After several tests, finally I can start an activity when an alert is > fired. I have used the example code from openintents.
<snip> > class ProximityIntentReceiver extends IntentReceiver > { > @Override > public void onReceiveIntent(Context context, Intent intent) > { > Intent i; > > String action = intent.getAction(); > > if (action.equals(PROXIMITY_ALERT)) > { > if (!alert_activated) > { > i = new Intent(); > i.setAction(PROXIMITY_ALERT); > i.addCategory(Intent.DEFAULT_CATEGORY); > > context.broadcastIntent(i); > int receiverCount = > context.getPackageManager().queryIntentReceivers(i, 0).size(); > Log.i("TAG TRACKBUILDER : ", "receiver count:" > + receiverCount); > if (receiverCount == 0){ > int activityCount = > context.getPackageManager().queryIntentActivities(i, 0).size(); > if (activityCount > 0) > { > alert_activated = true; > Log.w("TAG TRACKBUILDER : ", > "Activity found."); > > i.setLaunchFlags(Intent.NEW_TASK_LAUNCH); > context.startActivity(i); > } > else > { > Log.w("TAG TRACKBUILDER : ", > "no activity found"); > } > } else { > Log.i("TAG TRACKBUILDER : ", "broadcast > count:" + > receiverCount); > } > } > } > } > } You seem to be going through a lot of work just to launch your activity. Why aren't you just using startActivity(new Intent(context, InformationClass.class)); instead of broadcastIntent() and subsequent logic? If the issue is that ProximityIntentReceiver is declared in the manifest and therefore does not hold onto its state, then don't put it there. Instead, use registerIntentReceiver() from your parent activity. Then, your ProximityIntentReceiver will live as long as the parent activity does. > With this code I have a problem, only work correctly the first time. I > use a boolean variable to avoid that the activity be opened many times > because while the GPS point is into the radius of the alert, It is > fired and then a lot of applications are fired. > > There is some way to disable the alert when application has been > launched and when exit from this application return to enable the > alert? Try this: 1. If it is not there already, use registerIntentReceiver() as I described above, so it is controlled by the parent activity (in fact, it may work best if ProximityIntentReceiver is an inner class of the parent activity) 2. In the ProximityIntentReceiver, after you have received the first proximity alert intent, call LocationManager#removeProximityAlert() with the same Intent object you used in the previous addProximityAlert() call 3. Call startSubActivity() to launch the child activity 4. Implement onActivityResult() in the parent activity, and have it call addProximityAlert() again -- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ -- Available Now! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new M5 SDK! http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---