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.
Related
Hey guys I have 3 activity,
Activity A -> Activity B -> Activity C
This flow I want to perform in my application. I want this scenario in my Activity C
Scenario 1
On Back press from Activity C to open Activity B then again back press then open Activity A
Scenario 2
When something submit on Activity C, I want to open Activity A and I want to hide Activity B
So how can I do this through startActivityForResult. I check through this stackoverlow, but nothing works. Thanks
I'm assuming that the 3 activities are opened in order A -> B -> C, so they are in the backstack in that order. You can check the return values from Activity C, and act accordingly.
In Activity C, setResult(Activity.RESULT_CANCELLED) during onCreate(). That will make it the default return value when activity C is closed (back press or otherwise)`.
Then setResult(Activity.RESULT_OK) whenever something is submitted. After that, you can fininsh() that activity.
Whenever Activity C get closed, in Activity B onActivityResult(), check the return value. If it's RESULT_OK, call finish() (which will return to Activity A). Otherwise, do nothing, so Activity B will stay open
I have 4 Activities.
Activity A is where I want multiple types of custom objects to end up for processing.
I used one instance of startActivityForResult to connect from Activity A to Activity B, and from there I use FLAG_ACTIVITY_FORWARD_RESULT when I connect to Activity C. I call this one more time to connect to Activity D.
I can get any of the custom objects back to Activity A easily using the setResult(), my problem is I want to be able to get a Custom Object from Activity D, back to Activity C. Can I use startActivityForResult again from C to D, and when I call setResult on Activity D, will it point back to Activity C or pass down the line due to FLAG_ACTIVITY_FORWARD_RESULT?
Consider to use one host Activity as a navigation/task controller and multiple Fragments with callback results.
If you want to stick to Activities move all navigation logic to the root activity.
So I just want to clarify the life cycles a little. I have three activitys A(main), B and C. B is startet from A with some extra infromation, that it needs to show the correct content. Now B starts the Activity C (no extra content needed).
Can now (Activity C is in foreground) activity B be killed? If so, when pressing the back button, do I need to transfer that same infromation from C -> B, that was transfered at the first creation of B? Basically, what I wnat to know is, if extra content is used to start activity from parent activity, should this same extra content be used to start the activity from its child?
Thank you
Jaka
No need to pass back data from C -> B when you press back button.
On B's onCreate, store the additional data into private class variables and you can use it when the activity is restored.
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.
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!