I have 3 activities A, B, C. A activity has a fragment that holds a big amount of data. So does B. My problem is I go from A to B, and from B to C. And when i want to return from B to A with setResult() method. A activity starts from the beginning, not from onActivityResult(). I need help to solve the problem.
Related
I have 3 activities where Activity A start Activity B, and Activity start Activity C.
A <=> B <=> C
So when I go from Activity A to B, I use
this.overridePendingTransition(R.animator.slide_in_left, R.animator.slide_out_right);
From Activity B back to A (using back key eg), it I'll have
this.overridePendingTransition(R.animator.slide_in_right, R.animator.slide_out_left);
Similarly, if I go from Activity B to C, I plan to use
this.overridePendingTransition(R.animator.slide_in_left, R.animator.slide_out_right);
And same for Activity C back to B, I plan to use
this.overridePendingTransition(R.animator.slide_in_right, R.animator.slide_out_left);
Now my problem is activity B has both transition depending it is called by A, or return from C. I create the back transition during onPause(). However this is not idea, as activity B will be paused too when it is calling activity C.
What's the right way (or right place to place the above codes) to controlling the transition animation that depends if it is creating a new activity, or exiting the activity?
Thanks!
I am trying to implement a three step process via 3 activities.
Activity A can proceed to Activity B
Activity B can proceed to Activity C, can return to previous Activity A
Activity C can return to Activity B
I have a custom object which is used to retained all the variables across A, B, C. When I proceed from A to B, I just pass it through the intent.putExtra(), likewise for B to C.
When I return from B to A or C to B, changes are lost. I use finish() to return to previous in current implementation.
I also need to take care of the back button in that no changes are lost.
How can I implement such behaviour:
navigate between A <--> B <--> C
and retaining the changes into the object? (page loads with information from object in onCreate()
you can override onResume() function of the activity and call those changing methods there.
The startActivityForResult()and onActivityResult works perfect if there are only two activities are involved. But how can I handle this, if more than 2 activities exists?
Example:
Activity A starts a new activity B, that starts activity C, that starts activity D. I want to return the result of D to activity A along with finishing activities B and C. How can I do this? Can I loop through the activity stack and finish the wanted activities or must I start a new instance of activity A?
For short: A->B->C->D has to lead back to A with the result of D.
Going back closing each activity would be a good way of doing things, but if you need to jump from an activity to another and you're not using a TabHost, you could take a look at the APIDemo Reorder code
It jumps from an activity (4th) to a previous opened one (2nd) in this way:
Intent intent = new Intent(ReorderFour.this, ReorderTwo.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
In my opinion the most logical way is have the Activities take responsibility for this.
D returns d to C.
C returns d and c to B.
B returns b,c,d to A.
This will force you to consider the error conditions when the Activities don't happen in this cycle explicitly.
I have three activities, A, B and C.
User can start activity B from A, and then C from B.
I would like to have following. In C the user fill some field and click "OK"-Button. After that both activities B and C should be finished.
I don't like my idea, to finish A after starting B, then finish B after starting C, and then start A from C.
What is the best way to do that?!
Is it possible to finish parent activity from the child? If, yes, then that would be my solution. But i haven't find any information about that.
Thank you,
Mur
in Activity B, call Activity C with startActivityForResult. In the ActivityB.onActivityResult() method, call finish() when Activity C returned with a good result. This gets you back to Activity A.
try This
In Activity C Class
Intent mIntent=new Intent(getApplicationContext(),A.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(mIntent);
Support App starts activity A, then A starts activity B and finishes itself. After that activity B starts activity C.
Now the stack contains B and C, with C at the top.
Then I click a button in activity C, and want it to clear B and C and start activity A, i.e. I want activity A to be the only activity in the stack. How can I make it?
Edit: I made a test to use FLAG_ACTIVITY_CLEAR_TOP. But it didn't work in my case, because activity A is not running when button in activity C is clicked.
Set the FLAG_ACTIVITY_CLEAR_TOP flag on your intent to start activity A.
Edit: Is there a reason you can't leave A going? Then you could do as suggested.
Otherwise, another (more complicated) option:
In B start C forResult. When A is started from C, you could finish C with a result indicating to B to also exit.