Today has been a bit slow because I’m getting acquainted with all the new vocabulary, both from Java and the Android SDK. I’m still following the Android training from developer.android. I need to take my time to go over the methods and XML to really understand what each line does. I know most would just get the tutorial done as fast as they can to move on to more advanced things, but I’m doing this right now because I want to avoid “what did this thing do again?” or “what am I supposed to do here?”.
Following the tutorial, I created an input box with a button “Send” next to it. You input something (text) in that box and then hit send, which leads you to another screen or “activity” that will show you just what you wrote.
Simple? Not for your first time. The XML part was rather straight forward, you define the layout of the input box and button for your main activity (the app’s home screen). The tricky part starts when you have to link things to one another. On the XML button layout, you write onClick: and then the name of the method, which means it has to run when you click the button. This method needs to be defined in the .java file corresponding to that XML file. In this method, you put whatever you want do when you press that button. Then you have to link this method to the new class, which corresponds to the new activity. You do this by building a new “Intent” in the method, which is an object that can create new activities. In the new class which is invoked by the intent, you have to get the message which is located in the previous class. This is done by the intent object, in the previous class, you have to say to the intent object to carry/store the message. So you can retrieve this message and display it. And that’s it.
After that I started looking at the activity lifecycle and the different stages an activity can be at: created, started, resumed, paused, stopped and destroyed.
The first two happen really fast, usually when you click on an app, the activity gets created and started almost instantly. Then follows the resumed stage, which is when the activity is running and you as a user can use it. When it’s paused, the activity is partially visible and stopped is when it’s not visible. If the activity is paused then when you go back it resumes, when the activity is stopped and you go back, it’s restarted. Finally, destroyed is when you shut down the app completely.