Android resume from one fragment activity to another and vice versa - android

I want to create Android app where there are 3 main FragmentActivities, A (main), B, and C, also there are other sub activities. this app can go from activity A to activity B or activity C freely, and vice versa without starting new activity unless it is not started or finished. so how i can achieve this?
----- Edited -----

You can't. At any point in time there is only one Activity that is active. They will be finished and they will be garbage collected.
What you can do is set your launch mode to single task and see if it helps in your situation.

Use Navigation-Drawer or Swipe View..fragments are your solution. So you'll have FragmentActivity and 3 fragment A B C to replace

I will move activities layout to views, and write within one Activity, use hide/show to change to A, B, C.

Related

exit transition from activity not working

I have three activities (A, B and C) with an image view. Activity A has a small image view, B a mid-sized image view and C a fullscreen image view. From A to B I use
makeSceneTransitionAnimation for the transition. Start and Exit transition are working fine between A and B. From B to C I also use makeSceneTransitionAnimation. Thats is also working fine but when I go from C to B and then from B to A the exit transition is not working.
Is there some overriding process from C to B that affects the exit transition from B to A?
I found a solution that I am satisfied with for the moment.
My first approach was to monitor, inspect and manage the shared elements via SharedElementCallbackbut this does not seem to work as there are no shared elements in activity B when comming from C. So now when I am in activity B and I want to go to activity A, I check which activity I come from (A or C). Is it activity A then I simply use supportFinishAfterTransition. If I am coming from activity C I use makeSceneTransitionAnimation to activity A. The second case creates a new instance of activity A. Thats why I just finish the older instance of activity A.
I uploaded my solution on github to the repo "transition" in case somebody wants to use some code (github account is linked here on stackoverflow).
If somebody knows a better solution please let me know.

Activity back tracking in Activity stack - Android

I am having two activities, Activity A and activity B.
Activity A starts activity B.
So, the activity stack after some interactions will look like A -> B -> A -> B.
The problem:
I need to go the first activity A in the stack from activity B (last B in the stack). I am using FLAG_CLEAR_TOP as well as Intent.FLAG_ACTIVITY_NEW_TASK for achieving the same.
Right now, the activity A (stack pos 3) will be shown from activity B, but when I press back button, the activity B will be shown again (since activity B (stack pos 2) is already there in the stack).
How do I overcome this issue?
PS: I tried using launchMode singleInstance and singleTask for activities A and B, but that solution doesn't work for my app.
Thanks in advance.
Add finish (); after switching activites like
Intent intent = new Intent (activity_a.this, activity_b.class);
startActivity(intent);
finish ();
Avoid creating multiple instances of activities if possible. Android isn't designed to allow you to identify (and return to) a specific instance of an Activity in the stack, if you have multiple instances of the same Activity in the stack.
Depending on your application, there are different ways to solve the problem.
One way that may work for you is to use <activity-alias>, which allows you to reuse an existing Activity implementation by another name.
Another way would be to create another Activity class, that just inherits from the original, so that you have 2 classes with exactly the same code, but with different names.
The best way is to rearchitect your application so that you only ever have one instance of each Activity alive at any given time. You can do this by rearranging the task stack using Intent.FLAG_ACTIVITY_REORDER_TO_FRONT.

Replace a fragment from other activity than the host

I have a MainActivity with a container FrameLayout in which I change multiple Fragments (Fragment A, Fragment B etc).
In one of this fragments let's say Fragment A I have to open another activity (Activity X).
The problem is that from this activity when I press a button I have to change Fragment A with Fragment B (in the background somehow) and after that, slideout Activity X (with translate animation), and slidein Fragment B ,all this without restarting the MainActivity because I have to keep the state.
How can I do this?
Thanks
Android uses loosely coupled components as its main building blocks. As you know, Activities are one of the main Android building blocks. Thus, interacting between activities are very restricted to a few ways.
Passing data via Intents by startActivity(), startActivityForResult() etc. This way is useful whenever you are starting new activities.
Sending broadcast Intents. This could be useful once you want to send a signal to your another app's component.
Utilizing shared Application object.
Java static fields and some other ways.
In your case I would recommend you to use a Dialog Fragment instead of your second activity, if your second activity is just a login activity or something like that.
UPDATE #1:
If you really would like to keep your second activity, so I would personally recommend using local broadcast mechanism.
Also there are another way to get this done. You could start your second activity as startActivityForResult and then whenever user gets back from your second activity to your first one, your first activity can get informed by its onActivityResult method. There you could switch those fragments.

Manipulating back task stack in android

I have three activities A,B,C,D.
When I use activity B, then previous activity is A. I will write it as A->B.
So when I click back I go to A.
However I want to start activity D from B. But instead of tree A->B->D I need to alter it to A->C->D. How can do it in android?
There are many ways to do it.
You can have a lok at the below links.
First- Second- and this-

navigating between 2 activities in which one of them is graphics heavy

I have this situation that I am not sure about the right design/way of doing things.
I have an activity where user would spend most of his time (Call it Activity A). Then the user can go to another activity where it is more graphics intensive (Call it activity B). Activity B would have around 40 Imageviews that have looping drawable animations. The user will be navigating back and fourth between those activities multiple times.
Is the expectation to create Activity B every time the user navigate to it and reinitalize the the 40 views based on the stored Data in my application class (it has coordinates and the type of view created)?
Or is there better way?
Thank you
You can use Following flag with intent to resume same activity without recreating it:
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Instead of using activities, you can use fragmentA and fragmentB
When you switch between two fragments, data of them will not be lost.
learn about fragment here
you can use fragments with in the single activity. fragments are easy to swicth between another fragment. so did not lose data of another fragment.

Categories

Resources