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.
Related
This is my first time building a complex android app so I apologize if this is a vague question (please ask me to expand!) but I'm a little lost on how I should design/implement my application.
To make it easier, say I have a list of cars to choose from in the main activity.
Once a car is selected, it will take me to its specific settings page in another activity (the master/detail flow activity).
What I'm thinking of doing is the following:
Create a class for car with all of its fields as the various settings
Create a list of them in MainActivity
Once a car is selected, pass that specific car to the master/detail flow activity using intent
From here I'm a little confused, but I think that in the 2nd activity depending on the settings the user selects, the car in the list in the MainActivity will have its fields changed even though it was changed in another activity?
Is this the best way to approach changing settings for a list of objects initialized in the MainActivity, from another activity? I'm mostly confused on if I'm allowed to do that 4th point.
You will need to return the object to the first activity and update your list with the new data.
Start the detail activity with the startActivityForResult and then in your second activity after doing the modifications:
Intent returnIntent = new Intent();
returnIntent.putSerializableExtra("result", theObject);
setResult(Activity.RESULT_OK,returnIntent);
finish();
And then, in the first activity use the onActivityResult method to retrieve the modified object.
this is my basic Sketch from the App I wrote, my Problem is that I Navigate between my Activities with (black arrows)
Intent intent = new Intent(this, someclass.class);
intent.putExtra("pos", pos);
startActivity(intent);
I am not using finish() to go back since I dont know wether it recreates my previous Activity, or if it just goes back without recreating. The main Problem here is that i need to pass pos around while i really only use it in FlashCardActivity but when I go back from, for example FlashcardChangeActivity it gets recreated which is good, since I want my elements of my RecyclerView to be actualized. I need the pos there since I call a Function in my Database which returns all the elements of a certain Folder which I will display than.
So how do I implement this more clean and better without having to drag around the pos.
(I would also have a UML Classdiagramm and my Code but i think the Picture i drew shows my Problem better)
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.
I am building an app where user can select participants from the contact and also he can remove participants later if he wishes not to invite him.
Right now am able to open contact list with the following code.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
I am thinking to store the mobile number in an array,but how the user will know which contact he has selected from the above code.
I am confused on how to proceed.
Any help could be appreciated.
Instead of just starting the activity with an intent, you'll want to start the activity for a result. Take a look at the documentation here - the first example is even picking a contact.
Perhaps I'm not used to the Android development, but when I look, I expect everything to be done in order. When one activity finishes, the next starts. However, it seems that my code doesn't work that way. Take the following code for example:
for (int i = 0; i < 3; i++){
Intent myIntent = new Intent(Game.this.getBaseContext(), NextScreen.class);
myIntent.putExtra("something", i);
myIntent.putExtra("Opp", oppList.get(i).toString());
startActivityForResult(myIntent, 0);
}
It doesn't display activity one, wait for you to do what you do in that screen, then come back for the second activity. It immediately displays the third activity. If I click on the back button on my android emulator, it will show me activity two... and if I click back again, it will show me activity one... so it just kind of rapid-fires these activities onto the screen without waiting for you to do what you do in these activities. I'm sure I'm not the first person that's wanted to do something like this. Any idea what I'm doing wrong? How do you work around this situation?
Activities execute asynchronously. One way to serialize this is to chain the activites in your onActivityResult method. Pass to each (sub)activity an activity number, starting with 0 and have the sub-activity return it as part of the result. Your onActivityResult logic can deal with the response, then examine the activity number and fire the next activity (if there is one).
I don't believe you can queue up pages like this in 1 handy function. You'd be better off having a function nextPage which takes the current activity have moves the user to the next activity. This could be called everytime the user is ready to proceed to the next page (triggered by a button press or something).
Or just start the next activity on the button press directly