Activity inside activity - android

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.,

Related

How to scroll to the top of a ListFragment

My situation: I have two ListFragments (call them A and B) managed by one Activity which keeps persistent references to both of these Fragments. When I click a button in Fragment A, I replace that with Fragment B. The problem starts when I do the following flow.
A -> B -> (scroll) -> (back button) -> B
In that case, when I go back to Fragment B the second time, the previous scroll position is maintained, which I don't want. Instead, I would like for Fragment B to start with its ListView at the top of its content.
Things I have tried which do nothing:
Calling setSelection(0) in onActivityCreated
Calling setSelectionAfterHeaderViews() in onActivityCreated
Calling smoothScrollToPosition(0) in onActivityCreated
Interestingly, all of these work if I post them on a Runnable. However, when I do that there is a weird flickering the second time I open Fragment B.
So, how do I get Fragment B to automatically scroll to the top each time it is attached to its parent Activity? I feel like there must be something blindingly obvious that I'm missing, but I'm really stumped right now.
You're calling the right methods, but you're calling them in the wrong place.
I assume you have code that switches between the fragments and you call it when an item is clicked in A. So whenever you do the switch set the scroll to the top, something along these lines:
protected void switchList() {
ListFragment a = (ListFragment) getFragmentManager().findFragmentByTag("a");
ListFragment b = (ListFragment) getFragmentManager().findFragmentByTag("b");
b.getListView().setSelectionAfterHeaderView();
getFragmentManager().beginTransaction().hide(a).show(b).addToBackStack(null).commit();
}
And one important note: never keep persistent references to fragments in your activities. Whenever you need a fragment get it from the FragmentManager. This is crucial since on configuration change (like a device rotation, or when your app is suspended and restored) the fragments are recreated, and the reference you kept leads to a 'dead' fragment. Not only is it a major leak, it will also prevent your code from functioning. any change you make to the saved fragment is not reflected on the screen because the screen holds the newly created fragment.

Navigate up to last shown fragment

I've implemented a NavigationDrawer within the MainActivity which containts two Fragment. The second Fragment contains a ListView that opens a new Activity (onItemClick) that shows the according detailed data. (I guess that's pretty much the master/detail flow).
When I use the up button to navigate back I got shown the first fragment and not the second fragment with the ListView.
Any ideas how to solve that problem?
Make method in MainActivity for example setFragment(int whichFragment);
and set fragment you want in it, you should already have code that do that and than call that method in onBackPressed() method.
For your question about another fragment, well it depends on how your master/detail flow is suppose to work, it is not a problem to use another activity if you dont need left menu any more, but if you do need left menu then use another fragment.
Best regards

Access to the parent activity of a fragment

I have an activity that extends SherlockFragmentActivity. Clicking on any button in this activity makes that frame replaced with a fragment. Fragment contains a ViewPager that a ListView is in it. OnListItemClick event is located within the fragment. when clicking on any of the items in the ListView it makes the new fragment open, and this continues to be hierarchical. To open the second and third fragment and etc, Activity does not have control to replace New Fragment.
My question is:
How can I when I'm in a Fragment, come back to parent activity of this fragment?
Thanks
Have you ever gone through the official documentation for using Fragments in Android?
Please go through it atleast thrice I'd say cause it is the best place to start
learning about fragments. In case you still don't want to do that, here's a sample project(which is also provided by the same site) to start with.

Issues with activity group

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.

How to call an activity inside a fragment

I have created a fragment inside an Activity, and now I want to open another application/Activity inside this fragment, Result that I want is, both the activities should be seen on the display (it should not open in another window). Please let me know how can I achieve this.?
Nope you cannot achieve this, you cannot start an activity inside a fragment nor you can show a fragment inside a fragment. For showing multiple layouts in a single screen or activity you need to adjust your activity's layout file and arrange different fragments accordingly ...

Categories

Resources