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.
Related
I am currently writing a drawer layout as my main layout, with an embedded FrameLayout that I will be using to hold each “page” when an item on the drawer is clicked on. When the app first starts, an initial fragment will be show. Other fragments may be added/replaced later which is fine, however, my problem is that when the user clicks the back button on the very first “initial fragment”, I don’t want that particular fragment to be removed from the layout. Currently, it is being removed and it’s just showing a drawer layout with no other content (which makes sense). I want the app to automatically exit if the initial fragment was the last one showing and the back button is pressed, instead of removing that initial fragment and then after another back press, then it exits.
Things I have thought of doing:
Not adding the first fragment to the backstack. (If I do this, I can compare it with the classname of the fragment which is a somewhat longer string, or I can use a boolean value for once the first fragment has been placed (and not added to backstack), the boolean is set which allows the fragments to now be added.
Overriding the onBackPressed function of the activity
Does anyone have a suggested way of doing this or can think of a better way? Thanks
The first bullet point sounds the cleanest. You have no other need to handle conditions when back is hit, correct? If that's the case, it's less lines of code (removing one as opposed to adding several) and you get to keep default Activity methods as is.
I know that's not exactly what you asked, but I think the first bullet point is so clean, that I just wouldn't try something else.
I have implemented same in one of the app using my own Stack of fragment. and also implemented onBackPressed method.
Every time when user clicks on item in drawer i add fragment in stack and in back press once its length is 1 I finish the activity with message.
On item click -- Add/replace fragment in container.
OnBackPressed -- Pop fragments from stack and once its last one i finish activity.
Hope this can give you another option to consider.
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 a form, and I have chosen to divide it in two steps.
To do it, I created two layouts for a same activity. When the user complete the first form, I call the second layout with :
setContentView(R.layout.activity_form2);
The problem is, if the user wants to come back at the first step of the form, it's not running, because he comes back to the previous activity.
Is it correct to do that, or I need to use fragment?
Otherwise, how can I do to come back on the previous layout, and not the previous activity?
Never set different layout's for the same Activity. You can navigate to a different Activity or you could use Fragments.
Layout is set to the Activity and when you click back button Activity is popped from the back stack and previous Activity in the stack takes focus. So setting different layouts for the same Activity is not a good choice.
Assuming we have two Activities: List Activity and Detail Activity.
We have a "Save" button in Detail Activity which after saving, finishes the activity to go back to the List Activity.
I would like to know if we can have an alert dialog fired from "Save" function of Detail Activity so that it can stay over the transition of moving back to List Activity..
In other words, Can a Dialog exist outside the Activity? My understanding is that a Dialog is a child of an Activity and has to be destroyed if the activity is destroyed..
In iOS this is possible since the Dialogs are attached to the navigation controllers. Is this possible in Android? I am not considering fragments here..
If you simply want to display a message like "your changes have been saved" then in the Android world you would display a Toast. A Toast can even have a custom layout.
Another possibility would be to move your code to Fragments (which would be a good idea anyway) and then have an activity that acts as controller (i.e. creates and swaps the fragments). That should allow you to open a dialog while activating a different fragment.
You can choose two possible options:
You can stop the AlertDialog when the Detail Activity is dismmissed and then show it again in the method onCreate on the List Activity.
Another option is that you use a one single activity rather than two activities, and change the layout of the Detail Activity to the layout of the List Activity when you push the "Save" button.
There isn't an easier way to get what you want.
I have used 2 tabs in my app.
when i click on first tab it is showing an list view( default) and when i click on any particular item in list view it is taking me to the next activity to display the selected data. Here when i click on tab again i want that i should go to the listview screen which is default screen.
but nothing happens on clicking the tab but when i press the back button i m going back on the screen. but i want to go to home list view screen on tab click,
pls help me in this case...
You say you start a new Activity. This one can not call the first Activity where you have the tabs. Am I right that your new activity just shows the two tabs as well?
What you could do is the following:
In the second Activity react to the onclick of the tab. When clicked call finish() to close the Activity.
I am pretty sure, that you don't need to do the following. But I write it, if you need it for something in the future :).
In the first Activity call the next through startActivityForResult(...)
In the first Activity overwrite the onActivityResult method. there you can switch to the tab with the list.