//****************************************************************************// //****************** Intro. to Android- September 8th, 2017 *****************// //**************************************************************************// - So, "Model-View-Controller" is known as an "architectural style" in the world of software engineering; it's a standard way of building software that's been proven to work for a large number of projects -...but what exactly IS MVC? - As we were discussing, the MODEL is where our data is: business data, rules (usually stored as POJOs; "Plain Old Java Objects") - The VIEW is what handles displaying the UI, different screens, etc. - In Android Studio, this is mostly done via XML files; "In 1331, you had to actually code stuff in JavaFX, right? Well, nobody ACTUALLY creates GUIs that way; Java itself is rarely used for front-end stuff nowadays" - And then finally, we have the CONTROLLER; this is what handles all the user interactions (clicks, button taps, dragging, etc.), and processes it - Sometimes, the View/Controller are considered the "Front End", while the Model is considered the "Back-End" - Today, we'll be focusing on CONTROLLERS, since the Models you actually already know how to create (it's basically just creating Java classes, after all), and Android Studio has some really nice GUI tools to create the XML files by just designing the screen - So, first, let's talk about a few Android-specific terms: - ACTIVITIES are visual representations of an Android app; it uses both views and fragments to create a UI, and there's usually one per "screen" of the app (?) - These are where most of our controllers will go - FRAGMENTS are pieces of code inside activities that support multiple screen-sizes, different activities (swiping), re-using screens in other parts of your app, etc. - "In this class, you really don't HAVE to use fragments; the project doesn't require you to support multiple kinds of devices, but feel free to do so for extra credit" - It WILL complicate things if you choose to use them, though - VIEWS are single components of the UI, like buttons, text fields, images, etc. - "This is NOT the same as Views in MVC; this is a definition specific to Android developers" - VIEW GROUPS are basically layout managers (like flow-layout, grid-layout, etc. in JavaFX) that determine where the View/Widget should actually go on-screen - INTENT is an asynchronous message that lets the app request functionality from other components - "So, in 1331, pretty much everything you programmed was synchronous; but in Android, a LOT of what we do is done asynchronously; 'intents' are basically ways of queuing up those asynchronous actions" - SERVICES are background tasks that can run quietly in the background without user interventions - e.g. download manager that keeps downloading file after app is minimized; similar to daemons in other apps - "In our homework, these really aren't required" - CONTENT PROVIDERs are interfaces to shared application data, e.g. databases - A good example would be the list of contacts on your phone; ANY app can get that information by accessing it via Android's interface - "Similarly, in your app, if you want to let other applications access your data, you would need to create an interface to let them access it" - BROADCAST RECEIVER allows the app to handle events outside of the program's normal flow (e.g. Words with Friends can get recieve new moves even when the app is closed) - "Again, this is NOT required for your homework" - Now, ANDROID STUDIO is Google's official development platform; it comes with the Android SDK and Gradle already integrated, and is based on JetBrain's IntelliJ - "Now, every year there are some people who don't want to give up Vim, and that's fine; you can download the Android SDK and use that if you REALLY don't want to use Android Studio, but I think you'll have a lot easier job if you just use Android Studio" - When you create a new project, you'll have to choose a company domain; generally, the best practice is to use the REVERSE of your company's url (e.g. "cs2340.gatech.edu") - You'll also be asked which version of the API you want to use; I'd recommend not going before 4.4 ("KitKat") since you'll need to support Google APIs later on, but choosing a too-recent version of Android will limit what phones can actually run your app - THEN, you get to choose your app's startup activity: What's the FIRST screen to pop-up when your users open your app? - "Basic Activity" is probably a safe bet, but anything's good - Once you've done that, Android Studio will automatically create the code for our templates we've selected and setup our project. YOU ARE NOW IN ANDROID STUDIO. CONGRATULATIONS. - The screen on the right is the GUI designer; if you'd like to view the raw XML file that this designer is creating, click the "text" button on the bottom (next to the "Design" button) - Now, to run our app, we'll need to set up an emulator; click on Android Virtual Device (AVD) manager, pick a phone, and then hit the play button and it should run! - In Android-land, your Java project isn't saved as a ".jar"; it's compiled into an "APK" file - When your app has started, you'll need to worry about the "Activity Lifecycle", where it'll call "onCreate()" when the app is opened, "onStart()" when that activity becomes active/on-screen, "onPause()" if the user leaves the app, "onRestart()" when the app is opened again, "onDestroy()" when the activity is shutdown, etc. - There's quite a bit of nuance here, but one thing to know: if your app is paused, there's a CHANCE the OS will shut it down if the phone has run out of memory and your app isn't labeled as "high-priority" - NOTE: M3 files I gave out actually contain binary files I forgot to clean up, so in Android Studio, run the "Clean" process and "Rebuild" the project if it's throwing an error, and it should run fine