Using EditText in Activity Group - java

In my application i am using tabhost. And to control different activities i am using activity group. I have Activity A from which i am going to activity B. Activity B contains Edit Text, Spinner, Button etc. Now when i scroll the Activity B and press the device Back Button than it does not go to the previous Activity. It goes out of application.
Kindly suggest the answer.

This is the way the Activity lifecycle works for Activity Group. Try using fragments instead of activity group with your tabhost to get your movements. Also, please edit your question title to more accurately reflect the actual question.

Related

OnResume() is not called of the home activity when back pressed from a fragment

I am working on an android application. I have cardviews for multiple fragemnts. I have put these cardviews in the main activity. So when I pressed the cardview a fragment will open. So i will make these cardviews visibility as gone. But on back press the onResume() is not called. Hence the layout is not getting visible. I tried many things but did not work. What should I do?
From what I understand, you have an activity with a fragment. Then you load a new fragment and then you press back. This interaction will not fire the activity's onResume() because the activity has never been stopped. If there is logic you need to perform between fragments, it needs to be somewhere else. I cannot provide any more details without some more information.
I think first of all use the navigation on Android Jetpak

Retrieving an object when coming back to Activity

Here's the context of my question :
Context
I've made a Recyclerview that dysplay items thanks to an object called "identity_candle". When I click on items, it brings me to another activity with more description over the item. On this activity, there is a button to view more details about it that needs another layout by itself.
So when I click on the button it lands me on another activity.
IN SUMMARY, MainActivity (RecyclerVIew) => ItemActivity => "press button" => Activity or Fragment ? (Come back : Activity or Fragment => ItemActivity (keep previous object)
Problem
But when I want to come back to the previous activity it brings me error because the object state "identity_candle" is null.
Questions
What should I do ? Should I use fragment instead of activity when I press button ? (I've seen that object keeps their state between fragment and Activity but I'm not sure) Should I use SharedPreference ? If I want to create Fragment should I extends Fragment or ActivityFragment ?
This seems heavily rooted in understanding the Activity lifecyle. You'll likely want to go through that training if you haven't already. An understanding of onSaveInstanceState(), onRestoreInstanceState(), and Parcelables should get you there.

multiple fragments and activity all responding to button click in activity

I have a multi-fragment form dividing sections of a form. When the user is finished they hit the submit button at the bottom of the screen which is owned by the hosting activity. When the user clicks submit all the fragments should send their data to the activity and then the activity handles the networking. So I have onClick listeners set for the same button in every fragment, as well as the activity. However when I hit submit onClick only runs once, in some fragment (never in the activity), when it should run 5 times (because I have 4 fragments and 1 activity). Basically I need the fragments to deal with the click and then the activity deal with the same click.
Use the Observer design pattern where the activity is the Subject and the fragments are the Observers

Connection between activity and layout? How to change layout? How to start and destroy an activity?

I'm a total beginner with Android and Eclipse and I have few questions that will help me understand the philosophy of Android:
The activity does all the work "behind the scenes". Activities are connected to a layout in the XML file. When the activity is started, if declared in setContentView method, the connected layout will be shown. Activity can be independent, without any layout, it can be invoked by another activity and will do all the work without showing any layout.
Activity is something like a php file which is invoked by my submit button in HTML, and the layout is .HTML which shows elements.
Am I right with this one?
For example, if I want to change the layout of my app, I want to show Layout2.xml when clicking button in Layout1.xml. Then I have to destroy the activity which is connected with Layout1.xml and start the activity which is connected with Layout2.xml? Is this correct? Is there any better way to do this?
How can I (by which method) destroy/stop a certain activity?
Thank you in an advance.
The best bet is to read the Android documentation regarding activites at http://developer.android.com/reference/android/app/Activity.html
I will answer your specific questions here though
An Activity is a window that the user can see (or a hidden window if there is no layout defined). It deals with the logic of a part of the app that the user can see and interact with. If we take the MVC model (Model View Controller), the Activity is the controller, in terms of it controls which data from the Model is shown on the View (the xml layout).
If you want to show a new window/screen/activity you do not need to destroy the current one. You can open a new activity whilst keeping the old one in the background (in the back stack). With the use of fragments, you can have multiple fragments in an activity so rather than changing activities, you can change fragments in a single activity. For more information about fragments take a look at http://developer.android.com/reference/android/app/Fragment.html.
This point relies heavily on the activity lifecycle. When an activity is destroyed, it means it is finishing and this can be done by the user pressing the back button whilst on the activity, the activity calling finish() on itself or by the Android operating system destroying the activity because memory is required elsewhere (this can happen when the app is in the background).
When we say an activity is stopped, it means that the activity is no longer visible to the user. This can be the case where the activity is in the back stack (another activity is in front of it) or if the app has been put into the background.
This is a brief answer to your questions but I highly recommend you read the Android documentation to gain better knowledge.

Android pushing new activity on top of TabActivity and coming back

I have a question that I've been looking for answer to for several days with no luck.
So, to be as specific, I have TabActivity inside TabActivity and listview inside it (I call this entire screen "main screen"). That listview is populated from data sent from my database. Upon clicking an item of the listview, I start an activity but upon exiting that activity and coming back to the main screen, the listview is recreated and I was wondering whether there was a way to stop from being recreated.
Which method do I need to override to simply start and finish activity without destroying the main screen?
Edit--
I don't have FLAG_ACTIVITY_CLEAR_TOP attached to any of the activity

Categories