Saving changes in Activity after going to another Activity - java

So I have a Button in FirstActivity.java which when you press leads you to a second activity: SecondActivity.java, which has another button BackButton that leads you back to FirstActivity.java. The code in the first activity allows you to change the layout according to different conditions. Is there a way that if the layout of FirstActivity.java is changed, you press the Button to go to the second activity, then when you press the BackButton to go back to FirstActivity.java, the layout changes will be saved in the first activity?

You can use putExtra for send data to SecondActivity, and return data to onActivityResult.

Related

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

Multiple tap and multiple navigation activity

Help me solve my problem. I'm doing the transition between the activity using the startActivity method.
If I press n-times on the button that initiates startActivity, there will be n-transitions to activity. How to make the transition was only one?
You can set the button unclickable when you press it the first time.
The code is:
button.setEnabled(false);

Button in one activity to do the same as button in another activity

I am new to Android. In my application, in ActivityOne I want to allow the user to take a picture using a button. The picture is then stored in the gallery and displayed in an ImageView in ActivityTwo.
My question is: How can I add a button to ActivityTwo that allows the user to retake the picture if they don't like it when displayed in the ImageView. Basically, the button will do the same as the one in ActivityTwo. Do I need to write the same code for the button?
I have tried to create a separate that implements View.OnClickListener, add the functionality in the onClick method, and in each activity create an instance of that class attached to the button:
onClick(View v) {
int id = v.getId();
if (id == R.id.myButton) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
myfile = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
v.startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
}
However, this causes errors as the class is not an activity.
Any help is appreciated.
You can write the same logic for this second button, but as Naveen mentioned it would be easier to put the button on the first activity, leading to the camera. When the user takes a picture just add an imageview to the layout above the button using linearlayout on the first activity. Then the picture is displayed and the user has the option to retake it.
The best option is to let the user take the picture in the activity where it is needed. But if there is a need for you to use it in multiple places, you should extract the code triggered by the button in the first activity(The code that takes the picture) into a separate class. then you can call it from anywhere when needed.
#Subzero-273k Follow this.
In your activity make two different layouts. One, which shows your first button, remember to hide the other layout by setting the visibility.
Once user clicked the button1 which calls someOnClick(), hide first layout and enable another layout, which shows you the imageView and button2, onclick of button2 still calls your old function someOnClick().
How about this? As you dint mention what else you are doing in two different activities, I assume you just show activity one for single button.

How to pass a Radiobutton from one activity to other activity in android

I have 2 activities on android, in one activity I have 3 RadioButtons and a button called send, and when I select the first radiobutton and press the button send I want to send that radio button and his functionality to the second activity, and the radio button should be visible in the second activity until I decide to delete it from the second activity.
like:
Activity A:
-radioButton1
onclick(send)
activity B:
Received a reference of radioButton1 and his functionality.
is important to know that I don't want to start the second activity I just want to send a reference from the radiobutton from ActivityA to activityB.
The radioButton is a View, so it cannot be "passed" between activities. You have to create another instance of RadioButton with the same text as the selected before.
See more:http://developer.android.com/guide/components/activities.html#StartingAnActivity
I would prefer passing only feasible data of radio button from Activity A to B then re creating radio button at Activity B. Bundle the data and pass in while creatingg intent to another Activity.

Using EditText in Activity Group

In my application i am using tabhost. And to control different activities i am using activity group. I have Activity A from which i am going to activity B. Activity B contains Edit Text, Spinner, Button etc. Now when i scroll the Activity B and press the device Back Button than it does not go to the previous Activity. It goes out of application.
Kindly suggest the answer.
This is the way the Activity lifecycle works for Activity Group. Try using fragments instead of activity group with your tabhost to get your movements. Also, please edit your question title to more accurately reflect the actual question.

Categories