I would like to create a main intent(activity) in which someone can choose a track to follow. When a person clicks a button for a certain track, another intent will appear showing the markers along that track on a google map. There will be a "back" button which will bring you to the previous activity.
My question is... can I use a single map and, depending on the button that is clicked, to add specific markers to the map(and erase the previous ones) or highlight that track? How can I transfer a value from one intent to another?(I thought that all the buttons can start the same intent and depending on the value a specific track will be shown).
Any other ideas are welcomed :)
yes you can achieve this using single map.
just call clear() on google map object.
and secondly, on button click pass data using intent.putExtra(string,string)
method and read data by parsing bundle object in map activity
and accordingly add markers to your google map.
Related
My application involves tracking of vehicle movement through check gates
When a person posted at the gate clicks the Pass button against a vehicle number, that vehicle should be removed from the list. I have done it by calling the VehicleActivity class again with putting the gate id in key-value pair.
Intent intentClear = new Intent(context, VehicleActivity.class);
intentClear.putExtra(VehicleActivity.EXTRA_POSITION, Integer.toString(gate_id));
context.startActivity(intentClear);
However if the user presses the back button, the previous list shows up which may confuse the user. To remove the previous screen I can use Intent.FLAG_ACTIVITY_CLEAR_TOP, but then the information sent through putExtra gets removed.
Please suggest the best possible way of solving this as any problem in that list might make the vehicles stuck at checkgates.
To restart your current activity, simply call finish(); after startActivity();.
This will clear current activity after you start the new one and it doesn't exist in the back stack anymore.
I have a code that requires two edittexts, this information is used to display direction on a map. How can I submit this data automatically on activity start, without the need of a button.
Side question, is there a way to hide these edittexts? To prevent further manipulation by users.
EditTexts can be either disabled using editText.setEnabled(false); or hidden using editText.setVisibility(View.INVISIBLE);.
If you want to execute code on an activity start just write it into the onCreate(...) method.
I am learning android programming so be cool with me.
My question is, i am having for example 5 buttons.User clicks any one button out of 5 and clicks another button.So how to keep track of previously clicked button ids.So the 2nd button clicks output is based on the previous button.
Can any one throw me pointers on that.I am new to java and android.
I will recommend you to follow (Screen State) base approach; as below:
1.) Create Screen State class and assign each state a unique value.
2.) You should mention Screen state stack and the current screen state.
3.) when you press a button, call a OnstateChange() function. Which should determine the next screen (based on current screen and whether user moved forward or backward). If user moved backward, pop the screen from stack and mark it as current screen.
If you need to remember only the very last button you clicked, use a class member variable to remember something about it (the button's ID, or a numeric index, or something). You should set this member variable in the onClick() call corresponding to the button.
If you need to remember the entire history of clicked buttons, use a List implementation (ArrayList should be fine) and add() the information about the button (the button's ID, or a numeric index, or something) in the onClick() method corresponding to the button.
If you have different OnClickHandler's for each button, this is pretty straightforward. If you share an OnClickHandler, you will need to use some identifying property of the View you get passed in as an argument to onClick().
I'm adding dynamically created EditTexts to a layout (onClick button method). When I rotate the screen the added edittexts disappear. How can I add them to a bundle to put them in the onSavedInstanceState method? Or, is there another way to do this? I know I can save the text, but is there a way to keep the screen layout when I rotate it? If the user presses the button and adds five EditTexts(with or without typing anything) I need to save this layout when the screen is rotated (I basically need to dummy-proof my app :) ).
Thanks in advance!
You cannot add views to a bundle because they are not parcelable / serializable. The only stuff you can and should save into the bundle is the current state of the activity.
You could maintain a list data structure or a counter variable that keeps track of the dynamically created views. Also save the string values of the EditTexts. In onCreate you should interpret that information in order to recreate the views and their states.
you can't save a view. bundle is just a pair name-value. of course you can save the text and then render it again. the way is just you said.
onsaveInsatnceState(bundle save) save the text as save.putString('text1','bla bla') of course you need a loop to save all your edittext.
then in oncreated( bundle save)
you can get what you have added by save.getString('text1')
Views itselfs doesn't represents information that you need to save. Instead you should save their coordinates, width, height, value etc.
Your can save your view data into a class or into a arraylist.
when your fragment activity will restart than you fetch data from saveinstance state in oncreate function.
Use this function setRetainInstance(true). after using thing function your fragment activity will not destroy.
I hope I can explain this properly.
I'm making an android app that, when you open it, it connects to a JSON server, pulls down the data (GPS coords) and dynamically creates a "menu" based on what it received (View1). This will consist of a few buttons, which when clicked, will load a MapView (View2) with the coords gotten from the JSON represented as markers on the map.
I start off with setContentView(R.layout.menu) then get the data, onbuttonClick I load setContentView(R.layout.map) and draw the markers. The problem is, I have an onLocationChangedListener that goes through the code to set up the menu initially. When it tries to build the menu when the mapView is open, I get a force close. Unfortunately, this code also updates the user location and the locations of the overlays and re-draws the map.
My question is: Can I do a check on a layout to say something like if (isActive) so that I can perform actions only if the current view is in focus?
OR should I scrap the whole thing and start again with a better layout? (Suggestions welcome)
Summary::: I have 2 views (menu,map). Need access to same data across both. Currently works with setContentView() but gives me a Force Close when actions are performed on inactive view.
If I understand correctly, you are using setContentView(someLayoutId) to change each time what the Activity is displaying. This is not the way android apps usually work. When you retrieve a resource, you need a root element to reference it, that's why you get the exceptions when the View is not "active".
You have several other options to evaluate:
Create a new MapActivity to show the map
Create a TabActivity and add the map as a new tab
Use a ViewSwitcher to decide whether to show the map or not.