Lesson 6 from the mybringback Basic Android Tutorial Series was the one I’ve been waiting for. We are starting to learn Java and how it relates to Android development. I have no experience with Java programming so it’s all new to me. All the basic layout stuff is really interesting, but I remember it all from last year. I don’t remember any of the actual coding. I think I’ll just put up some code and attempt to explain what it means.
Okay, so line one simply sets up the package with the name I gave it when I created it. Maybe someday I’ll set up a custom URL so I can use that. Lines three, four and five bring in libraries (?) from Android so they can be used in our app. I remember from before that you need to import different things based on parts of the OS or device you want to use such as Camera, internet, mic, ect. Line seven creates a new class which is Public, meaning it can be referenced by other classes, and it extends Activity (imported on line 4) which gives the MainActivity class all the characteristics that the Activity class has. At this point we could call MainActivity the sub-class and Activity the Super-class.
Line nine is where it gets confusing for me. Mybringback says “The “@Override” means we are overriding the method from the super class (Activity Class).” I’ll just leave it at that and continue on. In line 10 we call the onCreate method from the Activity super-class. The tutorial didn’t really specify but I think this method is used to make an activity (makes sense, doesn’t it?). This would pretty much make a page as far as I can tell. We also want to make some changes to the onCreate method and that is why we bundle it with TonyIsAwesome so that it isn’t exactly the same as onCreate because that would be boring! Line 11 is where we actually create the method. Note how we referenced the super-class. In line twelve we point to what layout file we want to display.
Lines 16-20 didn’t appear in mybringback’s code. But I think I know what it is anyway so I’ll hazard a guess. Line 17 calls onCreateOptionsMenu which I assume is why there is a menu button in the top right corner of my app. I guess this is either a built in feature of Android Studio or it is something that the SDK started including around Honeycomb or Ice Cream Sandwich. It’s a boolean, so that means it can either be true or false. Line 20 indicates it is true. I’m not sure exactly what happens in line 19, or at least I don’t know how or why it happens. I know it makes a menu button and calls up a settings option in my app. Clicking on settings doesn’t do anything. Yet. I’ll add to it when I learn how to.
This tutorial also had us add a new folder under src/main/res called raw. He had us put a sound in the raw folder. I searched my PC for wave files and found one called JKIIstart.wav. I didn’t listen to it. I assume it’s a sound file from Jedi Knight II. It’s also short and I thought that would probably be good. This .wav file seemed to have caused some issues. AS wouldn’t associate it with a file type. I chose to just remove it until I found out what we were doing with it. I also tweaked the background I had made earlier to be less transparent and set it up in the splash layout.
I’d love to hear from in the comments. Am I missing anything? Can you fill in the parts I’m unsure one?
The Next Lesson talked about Android Activity Life Cycles. We didn’t do a whole lot in here other than some set up to get a working splash screen. I’m going to put up an Android Life Cycle chart for reference, but other than that I won’t say too much about this lesson, as when it finished we didn’t have anything new working. In fact we might have broke a few things.
Lesson Eight! Android Splash Screen with a Thread. This lesson caused me all kinds of problems, but not for any good reason. We learned how to set up a Java thread with a timer and edit the AndroidManifest file a bit. I learned that a thread requires a Try, Catch, and Finally section. In the Android Manifest we told it that we had another activity and specified which should launch first. We told it to start with our Splash Screen by labeling it with a LAUNCHER category. I believe we will set all other activities to DEFAULT so they will only be started when another activity calls on them. This what we did with our new Menu Activity.
The timer thread I talked about earlier was set to 5000 milliseconds so that it will stay there for 5 seconds, then run an intent to call the menu activity and finish the splash screen one. When all was said and done I tried to run my app in the emulator. It got errors. I spent 2 hours tweaking and pouring over my code trying to find them. It turns out if you spell “Activity” like “Activiy” it doesn’t know what to do. I was both mad and relieved when I found the error. It just goes to show how little mistakes can really throw you off in programming.
Travis (the mybringback tutorial guy) mentioned that Splash Screens can be a good branding tool within your apps. I’d like to say that I’m not sure I agree with him. In our example it just added 5 seconds of time that the user can’t interact with our app. To me that would just frustrate them if there is something they want to do. Maybe I’m missing something. To the real developers out there… What do you think? Do you use them?