Android Actvities problem for getting result - android

I have two activities A & b.
in A i have one button which takes me to the activity B. in Activity B i have one edit text. when user enter some values in edittext i m getting the value in some variable. and i want to pass this value back to activity A. i applied the Bundle concept bt it is force closing my app.
pls anybody can help me?
thanks in advance.

you should use Intent.putExtra() to transfer the value.

Related

How to change views in android

Consider we have two Activies: Activity A and Activity B, both have an ImageView. If we click on ImageView in Activity A, ImageView in Activity B should change to another image. Please tell us, how to achieve this by using interface
Your timely suggestions will help us a lot
Send some info about the clicked image in Activity A to Activity B using Intent. Then based on that info show the corresponding image in Activity B
As i understand what you are asking for has been asked many times. Its how to send data between activities. Here is an answer from another thread. Also you can check the Android documentation and read about bundles.

Closing the background activity which has the same name

I'm trying to develop an app which has two editText fields for entering location. So I made two java files
1.MapsActivity.java(with activity_maps.xml)
2.AutoComplete.java(with autocomplete.xml)
In MapsActivity while clicking the 'from' text field, it will open the AutoComplete activity and after clicking any of the suggestions in it will open a fresh MapsActivity and places the clicked item . Likewise for 'to' text field also.
I am using Intents to pass the clicked values. So at last, five activities are opened when the two text boxes are filled. When I click back button ,it is showing the auto complete activity used the previous time.
Question:
Is any other way to close a particular activity with same name running behind?
Is there any other way to pass values by super.backpressed(); ?
enter image description here
You can try using startActivityForResult() method. That way you can use the result from the second activity in the first and also you wouldn't need to start a new activity. You can read up on it here startActivityForResult
try to clear backstack/clear_top/single_top using the intent.
Just add/set flags in intent.
or
finish activity after startActivity.
or
you can override the onBackPressed method to call the specific activity.

Save data between multiple activities

First of all, sorry for newbie questions..
In my app I have two activities.
Activity A is in general a registration form with edittexts, autocompletetextviews, spinners and two buttons X and Y which leads to Activity B , practically a map activity. Applying startActivityForResult for button X I go to Activity B taking some data, then back to A ( onActivityResult ) then button Y leads with same procedure to Activity B and finally back to A.
The problems is that Activity A doesn't remember results from button X procedure when button Y ends its own.
Question1. Filling edittexts in activity A, going to activity B and back to A doesn't prevent activity A to hold this kind of data contrary to startActivityForResult and onActivityResult . Why is that;
Question 2: What is the proper way to save data from button X in activity A so that activity holds results both from the two button procedure when button Y finishes its own;
Thanks in advance..
#FKSI is correct that the proper way to do this is using Intents Extras. However, I use Several Fragments inside each activity and when I have a mix of many activities and fragments all playing together AND if the data is not a lot, I find it very easy to use a SharedPreferences. Using getApplicationContext() as the Context, saving any SharedPreferences is accessible from anywhere in the package of the app.
The proper way to send simple data between activies is using extras. Have a look at Android official documentation
If I dont misunderstand, you just want to save temp data. I recommend you to use Application class. An example can be found here: Example. Hope it helps.

Identify activity in Android?

I want to know which activity calls current activity.I have three activity namely A,B and C. i am calling activity C from A or B. In activity C i want to know which activity calls A or B.
I used bundle to identify activity but i dont want this.. Is any other smart way to find my case?
Thanks in Advance...
getCallingActivity()

Application crashes when user presses Back Button

Good day all, First of all, maybe i went about this the wrong way in the first place. Situation is, i have a listview that when an item is clicked, it creates an intent and calls startActivityForResult() to another activity, to be able to edit the entries in the row. and that other activity after editing the required values, returns back to the calling activity, when the user clicks on a save button. The activity then uses the row Id to update the item.My problem now is that, if the user presses the BACK button instead, the application crashes. i have been looking around and see solutions like using Shared Preferences or onSavedInstanceState(), but i don't know where exactly i should be putting the code? Any help as usual, will be greatly appreciated. Thank you.
p.s: when i look at logcat, its gives a NullPointerException for this line in onActivityResult.
Bundle result = data.getExtras();
If you are assuming you will have a result on the parent thread if the user quits the activity via Back then that is most likely the issue. Try testing if result is null before attempting to use it.

Categories

Resources