I am having a main activity and two fragments. By default the first fragment appears on the activity (Let's call this fragment 'A'). On a button click I am adding second fragment to the activity (Let's call this fragment 'B'). I have set the screen orientation of the activity as portrait in manifest.
Issue I am facing is that when I call the camera from fragment B and I take an image in landscape mode and clicks on the tick icon in camera intent, my application is coming back to fragment A instead of fragment B.
It will be helpful if anyone can suggest me a solution for this issue.
In your onActivityResult() method, you may want to set which fragment you want to load after taking a picture.
Related
I have an app with a single activity showing a fragment to the user. On a click on a button, the activity shows another fragment but keeping the previous one in the backstack. I have now two problems:
On rotation (particularly in the second fragment), the data entered in the EditTexts is cleared
I want the backstack to be also restored with the text previously entered in the second fragment.
The problem is that when I save data to bundle using OnSaveInstanceState(...), I successfully get it again from OnViewCreated(...) but when I use editText.setText(str), the text is not shown.
At the moment, I think this is because the fragment is then destroyed and recreated by the parent Activity.
How can I do to make it work properly?
Thanks.
Make your fragments retainable:
setRetainInstance(true);
See the following guideline on orientation change state android orientation changes `
I have one activity with ListView and 2nd activity which have ViewPager. Now I want in one activity if status true then go to 2nd activity `
Intent n = new Intent(one, two);
startActivity(n);`
But here problem is it giving opening animation is any i can do within that 1st activity
any way i can avoid that animation and it look like it is same activity
or i have to redo full code and this inside 2 fragments ? so have one fragment activity and then but one activity code inside fragment and two activity inside fragment which will have view pager.
Paraphrasing you, your are trying to call activity B from activity A, based on a result, which is an item picked from list item, however you wanna avoid any sort of screen transitions (animations) when moving from one another.
I may be wrong but my google search didn`t revealed any way to avoid transition between activities.What your could actually do is to refactor your code using fragments and sort them out within the parent activity view group in a way that fragment B maximizes itself or pops up over fragment A pausing it.
Brs.,
I have an Activity with a fragment in front. now when i use StartActivity() the fragment is first removed and you can see for a half a sec the Ui of the activity before it moves to the next Activity...
any idea how to keep the fragment in the front until the last moment before switching to the next Activity?
Thanks
I am using fragments in my app. Below is the screenshot of my app. Everything looks fine on activity launch. But, when I change the screen orientation, the layout overlaps itself while scrolling. Any ideas what is wrong?
EDIT (Solution):
I found out what was wrong. A new fragment was added on orientation change. I was previously using fragmentTransaction.add(...), I replaced it with replace method.
For future vistor's understanding...
You are most likely adding your fragment in your activity's onCreate().
When your device is rotated, your activity is destroyed and re-created, but it also recreates any added fragments.
With these two things in mind...
onCreate is called and you add a fragment to your activity. You have one fragment.
You rotate the screen.
The activity is destroyed and re-created. Your fragment is destroyed and recreated. You still have one fragment.
Your activity calls onCreate() as a part of its recreation, which adds a fragment to your activity. You now have two fragments.
If one or both of your fragments have transparent backgrounds, both may display at once, as is likely the case here.
Either use replace instead of add (which you have done), or better, only add the fragment in onCreate() if savedInstanceState is null. If it is null it means it's the first onCreate() call.
I have an app in which I am implementing a tab bar with 3 tabs. In first tab I am implementing multiple activities by using activity group.
In this activity group I have 5 activities. In the first activity I am having edit texts, I am getting the data into edit texts from another class and then navigating to another activity by clicking a button. When I am coming back from second activity to first activty I am not able to see the selected data. It is showing the page without selected data.
I don't understand this.
From the documentation:
This class is deprecated...
And now coming to your question, you said:
... When i am coming back from second activity to first activty i am not
able to see the selected data...
It is default behavior of ActivityGroup, when you move forward, your current Activity's state is not saved and when you come back to previous Activity, it is started again and onCreate() is called again.
its because, in Activity Group Implementation, all the activities are re-created and then generates view, and then adding this view in window activity is displayed. So, everytime a new activity is displayed, as activities are re-created.