In my project I have an activity A and a dialog A1 inside A. From A1 I can call to activity B. In activity B have some string value I want to get and set it on Edittext in dialog A1 that had value already when finish activity B.
How can I do that?
Make a DialogFragment. Add it to the screen with a FragmentTransaction when the dialog needs to be shown. Either keep a reference to it while it is showing, or give it a tag when you add it so that you can find it later by its tag.
Use StartActivityForResult to start the next Activity.
Use onActivityResult to get the result of the second Activity. If the dialog is showing, use some public method you define to manipulate it. If it's not showing, you could just show it again with the new information.
Related
How to remove all the activities except HomeActivity.
ex:
A(HomeActivity)->B->C->D
now call B activity again removing C & D activities. I'm sending some data from D activity to B activity through intent. I have next button if i click next button then this process will be done. If I backpress then my process will be D->C->B->A
When you're going from D->B, use intent.setFlag(Intent.FLAG_ACTIVITY_CLEAR_TOP);
It will close all of the other activities on top of it and this Intent will be delivered to the (now on top) old activity as a new Intent.
FLAG_ACTIVITY_CLEAR_TOP
Then you need to create static activity variable in both C & D activity.
Just like this
//create static variable
public static CActivity cactivity;
then initialize this variable in onCreate of Activity.
//initialization
cactivity=this;
Finish that activity where you want
// use this where you want to finish activity
CActivity.cactivity.finish();
Make sure Activity must be running in background other wise you app will crash.
what I would of suggest is a not-so-smooth solution but instead of start activities for all of those replace them with a startActivityForResult, search for the result code and if it is returned from the activity (that is for you to handle of course) then call finish with all activity in the way with the result code until you reach your home activity.
Is there a way that from the activity i want to go to another activity with multiple fragment and select a fragment that i want to focus it.
Assuming you want to move from Actvity A to Activity B and make Activity B show a particular fragment. You need to pass an extra containing some form of identity(Eg. the name you gave to your fragment) of the fragment you want to show to Activity B. Then in onCreate in Activity B read the extra you passed to it to determine which fragment to setup in Activity B
Suppose i am having an activity (let's say activity1) and i have given a command for doing some long process. Mean while i am starting another activity (activity2), during this time if the activity1 finishes the process and shows the result in an alert box, then how can i make this alert box of activity1 appear over activity2? What i have noticed is that, the alert box of activity1 is only visible when i move back to activity1. Is there any way to do this? Ignore if the question is irrelevant, as i am just a beginner in android.
Before using two activity, you have to save the state of the activity and restore the another activity while come front. This is easily done by onRetainNonConfigurationInstance() and getLastNonConfigurationInstance() method. Please refer this link.
On Android, if I added a Dialog into the screen and another Activity opens, how can I get from that Activity all the open Dialogs?
I need to close one of them.
You should create a class and extend DialogFragment and in onCreateDialogreturn your dialog, then show this dialog fragment with a specific tag , after that , you can find this dialog by using activity.getFragmentManager().findFragmentByTag("the tag").
Don't hold a reference to your dialog (local or global) because the activity can get recreated and it will leak the reference in the memory, just get the reference with the findFragment method.
If you are in a fragment , you can use fragment.getChildFragmentManager(...) and do the same.
Good luck!
When another activity opens, your current activity will go through the onPause() state. More info on it can be found here.
In the onPause() call dialog.dismiss() and you should be set.
I've got an activity, call it A, that when initially opened I would like to programmatically open a another dialog theme activity, B, over the top. The user would select some info from the dialog activity and return to activity A. When resuming to activity A at some later point the data set would be available, so the dialog would not need to be shown.
The problem is attempting to start the dialog activity from activity A's onResume or onCreate methods causes strange and undesirable behaviour. The task appears to kind of freezes for a good few seconds and then the dialog is displayed correctly, but activity A isn't shown behind.
Thanks
Peter
check this:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/CustomDialogActivity.html
i think u should create activity as a dialog.then it helps
u can set style and theme for ur activity by this..