I have registered proximity alert in one activity and want to update the coordinates from another activity. How do I do that? I have already tried creating an unregisterProximity method in the 1st activity but it doesn't let me make it static.
Any idea?
pass the coordinates from one activity to the other or use locationManager.removeProximityAlert(proximityIntent) with the same proximityIntent for when it was created
post code and add more info cause your question is not that clear
Related
Can We write an event for clicking App Icon. I need to display a string during the Application icon click. Can anyone help on this. Thank you.
Firstly the question is where you want to display your string. As you didn't mention developing a widget or anything else but an Android app, my guess is you want to display it in your app.
So the closest convenient callback to the start of your app should be the onCreate method of your Application class. For this, you will need to extend the application class. You can see how to do it here:
https://medium.com/#balakrishnanpt/android-application-class-a8a1d64c82d1
At this point, you will be limited to showing a Toast message as you don't have any Activity yet.
As an alternative, you can create your first launcher activity and display your text in it's UI from the activity's onCreate method.
I am designing an android app where I want to list all the restaurants in a particular location. This happens on the launch of the app.
As the location changes, the list of restaurants should change accordingly even if the app is already opened.
Whatever examples I got on google do this populating of restaurants on the click of a button. But in my case it happens on the launch and if app is already launched then also depending on the location the list should change itself.
I have made a MainClass under which there is a subclass of AsyncTask and this subclass has a class which implements LocationListener.
But problem is this I have to call doInBackground() method again in onLocationChange to get the results automatically when location gets changed.
Please guide me what should I do?
Put all the logic you have for obtaining the user location and gathering new restaurant data into a Service. The Service can listen for your location updates (which hopefully are set to sparse interval if you want it running all the time) and then update the list with your AsyncTask whenever a significant enough change that requires new data occurs.
You can bind to the Service in an Activity when it's in the foreground (between onPause() and onResume() methods) to get the latest information and register as a callback if the data updates during the period while the Activity is visible to invoke notifyDataSetChanged() on your list.
You can read more about creating a Service bound locally in your application here.
HTH
Use some ArrayAdapter for the restaurants list and save it's instance in the Main class, then whenever the location changed use the AsyncTask to retreive the nearby restaurants and onPostExecute replace the ArrayAdapter internal list and call notifyDataSetChanged().
Listen to location changes in your main class. Upon receiving a (significant) change start an asynctask to query the restaurants. Pass the results (e.g. array of restaurants) to onPostExecute and update your UI accordingly.
Maybe disable updates while restaurants are being queried or cancel the query and start a new one on each new update.
I am currently working on a task where i need to fetch the locations from GPS.
The concern i am having here is that once i obtain the location & the task goes completed, after this if the application goes in background i do not wish to obtain any locations until & unless my application is back on screen (foreground) whatis currently not happening. (kindly note here i am not talking about switching the activity from one to another via intent as my app has only one screen & one activity).
I wish to know what place exactly the code to handle this situation must go & how can i do achieve this. I have tried with setting the instance to null & remove update but it proves ineffective. May be i am putting it at wrong place i am putiing it outside onCreate() inside the class extending activity.
Call requestForLocationUpdates() in onResume()
and removeUpdates() in onPause()
Once I obtain the location & the task goes completed
If you just want one Lat, Lon fix: don't use the tracking mode, instead use : requestSingleUpdate()
I have implemented a LocationListener activity to get the lat/lon coordinates. I launch a MapActivity and want to get the current location and show it on the map. Now I'm confused. What is the best approach to show a progress dialog while fetching the coordinates?
Start an activity for result (LocationListener) and show a progress dialog while waiting for the coordinates to be delivered.
Implement a getCoordinates() method in the LocationListener activity and just call it once i need it (in a thread?)
Include LocationListener into MapActivity and let it continuously update field vars from onLocationChanged()
Is there any better solution? I'm pretty sure there is, actually i don't really know what I'm doing right now... :-/
A good model for displaying location(s) on a map can be found on the android official guide. Check this, and scroll down to "Helping the user decide on where to go".
Firstly, I know LocationManager doesn't have to be called in an AsyncTask as it's already non UI blocking :)
I have an activity which
1. Gets the users current location
2. Calls a webservice to retrieve a list of specific POIs around that location.
The user can choose to view the results as map or list using a TabActivity. Bearing this in mind the AsyncTask to get users location and call to webservice is managed by the TabActivity view rather than either of the docked views.
So I want the TabActivity to start an AsyncTask which first gets the users location, then calls the webservice. A progress dialog prevents switching views using the tabs during this process.
It's pretty much all working apart from getting the users location from the AsyncTask. The webservice code is written, the mapping and overlay code is written, the task progress dialog copes with orientation changes.
The focus on location is speed rather than accuracy. If the user chooses to view results on the mapview then I will provide a 'My location' button which will enable a more accurate location to be obtained. I just want to initially get a rough location and return the search results quickly.
Maybe I'm going about this the wrong way. Maybe I should display the map view, let the map activity find the current location, then call just the webservice in the async - but then what if the user taps the list view tab during the location phase ? I was also going to allow the user to specify their default view - some people may prefer a list to a map. In this case I would have a listview which had to retrieve the location.
Thanks for any advice
Martin.
I sussed it.
The problem I was having was that the LocationListener was not being called in the AsyncTask.
The reason for this was that although I'd created and prepared a lopper in the thread I hadn't called Looper.Loop()
I start the requestLocationUpdates, kick off a timer. Either the locationmanager responds with a location, or the timer expires. At this point I call looper.quit() to ensure things return to normal.
Seems to be working. You also have to remember to respond to the back button etc, cancelling the timer and looper if the AsyncTask is cancelled.