Starting activity/collecting data/destroying - java

I would like to have 2 activities, in one activity 2 textboxes and in another acitivity Map.
When I click on Textbox in first one, to open another one, pick place, click Done and close Map, destroy that activity, and fill 1st text box in first acitivty with choosen place. When I click another textbox, need to open same map acitivity but from start.
Any tips how to do that in a right way, opening 2nd acitivty, transfer data in textbox in first one, destroy 2nd, and same again.
This question is without code, it doesn't need to post code from acitivities.

Run the second activities intent with startActivityForResult() method. After user picked the place in the map, but the put the String that you got from your map into intent before finishing second activity. Then at your first activities onActivityResult method, get the String you put into Intent and set it into your Textbox.
You can find detailed tutorial here:
http://developer.android.com/training/basics/intents/result.html

Related

Passing values between several activities

I've an issue with passing a variable back to the first activity.
My app starts with one activity, which opens a second one, which opens an third one, which opens a forth, which opens the first activity again.
Now I want to get a variable, which I get from a user input in the third activity in my first one. I already managed to pass variables between two activities there and back with onActivityResult() but I do not get how to manage this between more than two activities.
use bundle
you can use Bundle for move the value from first activity to second activity
check this link ---> [here] (Passing a Bundle on startActivity()?)
if use value in several activity you can use SharePrefrence or you can make
class extends Application and make value in the class and use the values in several activity
be careful if close the app destroy the values
You can use shared preferences to access variables in all your activities or use can use this method:
When going from fourth activity to first use startActivity(intent) and add the variable as an extra in intent. And in first activity override onBackPressed. This may not be good practice but it works.

How to display text in a new activity when two radio buttons from two different activities are clicked?

I am using Java and Android Studio. I have one activity with a few options to select from, and once one of them is selected, they click the button that takes them to the next activity. They do the same thing again except this time when the user clicks the button it takes them to a new activity where it displays the results based on the two radio buttons clicked previously. How can I do this?
You can send some variable through intent and onCreate() method of the second activity, you can use that variable to differentiate your functionality.
This video demonstrates the functionality of the radio button: https://youtu.be/zJG9Prn3vZ0
In this video you can know how to pass arguments to another activity: https://youtu.be/OMCctaE66b8
Hope that helps you to solve your problem.
You cannot declare a method inside another method. Put a closing brace after onCreate.
When you are opening a new activity, you are doing it with an Intent. Put the values you want to send (bool clicked) the new activity inside the intent

How would i resume the last viewed activity after the user has been closed the application?

How would i resume the last viewed activity after the user has been closed the application. It is like, If the user open the application, the first activity will appear and when the user click the button it will proceed to the next activity, if he close the application and open again it will still show the last viewed activity. how would i do that? please help me.
Thank you,
I think you should use sharedpreferences. And in every activity you open, you have to put a value on your sharedpreference so that if you open again your application it will check the value of your shared preference then compare it, call the activity that fits the value you got. Hope it helps :)
You need to track his last activity then, keep it in a database and whenever he returns, look up his last activty in the database...the other way is cookies but not adviseable ....
Place this below line in AndroidManifest.xml for your activities in <activity/>.
android:launchMode="singleTask"

3 Activities in Android Application

I made 2 Activities and started a second activity by clicking on a Button. All is good...
But if I add third activity - nothing works - I can't start neither the second activity, nor the third activity...
Program scheme:
First Activity has a Button, which starts the second Activity
Second Activity has a Button, which starts the third Activity
There shouldn't really be a problem if you have written it correctly. I recommand taking a quick look on the tutorial about creating a basic program in the training guide released by the Android developer team. They give you an idea on how to make the first button, just add this method to your second button instead of receiving text back.
As mentioned above, we need more details and you should also check your manifest file.
There isn't really much more we can help you with when you give us these details. Sorry.

Android ending activities

I go through few activities and when I want to go back to main window I use FLAG_ACTIVITY_CLEAR_TOP but if I press back button then I would go back to other activities that I went through.
Briefly speaking I want to go to main activity and after presing back button it wouldn't go to other activities.
EDITED
This clossing all activities is used to complete logoff process in another words it shouldn't user let to go back. I can't use BackPressed(), because I am using putExtra and getExtra. Maybe someone could write small sample. Because I don't understand flag system.
Use FLAG_ACTIVITY_NO_HISTORY on Activities you don't want saved on the stack. When the user presses back he/she will go to the last activity that didn't have that flag set.
You can override onBackPressed in your activity and start your desired one with the flags:
FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP

Categories