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.
Related
I am having 2 activities, in each activity I am having a view-flipper and button. When the button in 1st activity is clicked, I want to view the 2nd activity's view-flipper child. How to do that? Is that Possible? If yes, please tell me how to do that.
Thanks in advance.
You cannot directly interact with views between activities. Instead, you should pass data in an Intent when you call startActivity() from the first activity. The data should tell the second activity which view to start with. For example, you can send the name or index of the view. You can learn more about sending data in an Intent from the official Android documentation.
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.
I have an Android app with multiple activities. The main activity communicates over a network and can launch or dismiss various other activities depending on commands it receives over the network. When an Activity is dismissed I don't want to finish() it, just move it down the stack so it's no longer the top activity. What I really need is a FLAG_ACTIVITY_REORDER_TO_BOTTOM but there is no such thing.
There's an intent flag called FLAG_ACTIVITY_PREVIOUS_IS_TOP and the name implies something like that but I don't understand the description:
"If set and this intent is being used to launch a new activity from an
existing one, the current activity will not be counted as the top
activity for deciding whether the new intent should be delivered to
the top instead of starting a new one. The previous activity will be
used as the top, with the assumption being that the current activity
will finish itself immediately"
Could someone please decode that for me, and if it's not what I want IS there some way to tell an activity to submerge itself below the previous one?
This isn't possible. The activities are stacked and you cant put one back under the other. It sounds like you may want to create a class that extends Android’s android.app.Application.
I found this tutorial online and it looks good. Good luck.
Extending Android's android.app.Application tutorial
You cannot move an activity below a certain activity into the android back Stack. The only way to move a activity in back stack is to open another activity on top of it. You can move an activity on top by creating a single instance of activity using FLAG 'singleTop' in this way your activity will be moved to the top of another activity and only a single instance of activity will be there in stack.
More information about activity back stack and Flags is available here.
Go through this information and all your doubts will get cleared about back stack.
I have two activities, Activity A has a button "Load image" which should let the user select an image, but I want to process the chosen image on an other activity B.
I think this is a common scenario, how should I handle the activity flow??
This is what I came so far(which I don't like)
Activity A--> Gallery --> Activity A --> Activity B
Activity A's onActivityResult() only gets the URI and starts Activity B, so It kind of a waste to recreate the activity just to execute 5 lines and be destroyed (insn't it?). I would like something cleaner or more direct. This is just an example, anything is welcome:
Activity A--> Gallery --> Activity B
EDIT
What about this?
Activity A--> Activity B--> Gallery--> Activity B
Is it a better approach or is it the same thing? I mean, will i gain something (performance, cleanness).
EDIT 2
As #Gaurav said, a workaround option would be to use 2 layouts instead of 2 activities thus no need to directly deal with my problem. I must say this should do for me as activity A is very thin. But for the sake of knowledge, i will welcome a "direct" answer to my question.
EDIT 3
Finally, having both layouts in the same activity didn't work (though it was a very attractive solution). My Activity B is based on libgdx (opengl), and i'm getting some nasty deadlocks when onDrawFrame is not called. So to avoid future untraceable bugs of this kind, I'll separate my activities. I'm going for Edit-1 solution, any comments would be appreciated.
I think there is no other way than to call Activity B in the onActivityResult of A.
i'm trying to make an app for nexus 7.
how can i display multiple activity to red area when the button is clicked??
Btn_A call activity A
Btn_B call activity B
Btn_C call activity C
Btn_D call activity D
i'm really need a example for this.
You should use fragments in this case.
You can find some useful examples in the API demos.
Tab activity is the best for that scenario. Please read the below link for tab activity.
http://www.androidhive.info/2011/08/android-tab-layout-tutorial/