This guide is available to download as a free PDF. Feel free to copy and share this with your friends and family. Introduction to Android Development There are two primary ways to develop an Android app. The first is to write it from scratch, most likely in Java. But this, of course, assumes you already know Java or After so many years, one would think that the mobile market is now saturated with every app imaginable to man - but that's not the case. There are plenty of niches that still need to. Before diving in.
But what if you’re itching to get started right away? The other option is one of the point-and-click app builders on the market. Many of these target enterprise users (and come with an enterprise price tag). But MIT offers its “App Inventor,” an online tool that allows you to build your app visually. You can accomplish some neat things with App Inventor, which will keep you busy until you can dig into Java and access all the powerful features of the Android platform. In the sections below, we’ll build a prototype version of a simple “scratchpad” application, which will store the text you type into it. We’ll do this first in App Inventor and preview the results in an Android emulator.
App Inventor cannot connect to emulator. Ask Question. Started evaluating MIT App Inventor (ver 2.2) on Windows 7 (from Administrator account). Since I don't have Android devices, I have to use an emulator. AiStarter.exe and emulator.exe both work when explicitly started, but. This method provides the benefit of seeing the app on your Android device just as if you were using the MIT App Inventor Emulator application. This option also does not require a wireless network connection (see Figure 2.11 ).
Then we’ll extend this application with the ability to select from among multiple files, making it more of a “notepad.” For this type of improvement, we’ll need to dive into Java and Android Studio. Let’s get to it. Why Develop for Android? There are any number of reasons you’d want to create your own Android app, including. Necessity: It’s the mother of invention, after all. Maybe after looking in the Play Store for your dream app, you realize that it’s something you’ll Learning a programming language is popular.
But is it for everybody? Before you commit to it, do ask yourself the following questions and be honest. Because no one else has yet.
Community: Developing something useful and making it available for free (particularly as open source) is an excellent way to Open source development is the future of software. It's great for users because open source software is usually available gratis and often safer to use. But what compels developers to contribute code for free?
Without open source contributions, there would be no Linux, and Here we explore whether or not Android is really open source. After all, it is based on Linux! (or at least no Android as we know it). So consider giving back!. Learning: There’s are few better ways to gain an understanding of a platform than to develop for it. It could be for school or your own curiosity.
And hey, if you can make a couple bucks off it in the end, all the better. Monetization: On the other hand, maybe you’re going at this to make money from the start. While Android was once considered the “low-rent” district of app revenues, this has slowly been turning around. Business Insider that Android revenues are expected to overtake iOS for the first time in 2017. Add-on: Developers often create apps in general as a way to promote, access, or otherwise complement an existing product or service — like A game controller isn't a terrible remote, but it’s not a great one, either. A tablet or, in some cases, a smartphone provides a better way to access console features.
Whatever your reason, app development will challenge your design, technical, and logical skills. And the result of this exercise (a working and useful application for Android) is a great accomplishment that can serve as a portfolio piece. There are many avenues to creating your app, including different toolkits, The world of mobile app development is still going as strong as ever. If you want to get started, it's not too late! Here are the languages you should think about learning., and The Google Play Store isn't your only option when it comes to downloading apps - should you give the Amazon Appstore a try? At a high level, these break down into the following two categories.
Point-and-click Apps If you are a complete newbie to development, there are environments that let you build an Android app the same way you’d create a Powerpoint presentation. You can select controls such as buttons or text boxes, drop them onto a screen (as shown in the image below), and provide some parameters on how they should behave. All without writing any code.
These types of applications have the advantage of a shallow learning curve. You can typically jump right in and at least begin laying out your screen.
They also take a lot of complexity out of the application, as they’re designed to handle technical details (like object types or error handling) behind the scenes. On the other hand, that simplicity means you’re at the mercy of the tool’s creator as to what features are supported. In addition, a lot of these tools are targeted at large companies and can be expensive. An exception is web application, which is functional and free. After signing in with a Google account, you can click together an app in a couple minutes, and preview it either on your phone or via an Android emulator. Write from Scratch The other option is to write your application from scratch.
This is probably different from what you’re imagining — it’s Hollywood and hacking do not get along. While real-life hacking is hard, movie hacking often involves just pounding away on a keyboard like your fingers are going out of style. It’s typing code one line at a time into source files, then Compiling your own Linux kernel is one of those geeky, technical things, right? We've already covered a few reasons why you might want to do this - now is the time to try it yourself! Into an executable application. While it may sound boring, in reality, much more of your time in programming is spent in design, or thinking through how things should work. Ask most developers, and they’ll say they spend only 10-15% of their time on code entry.
So you’ll spend most of your time daydreaming (productively) about what your app should do. You can The world of mobile app development is still going as strong as ever. If you want to get started, it's not too late! Here are the languages you should think about learning. The “standard” way is to write apps in Java, consistently one of the most popular languages in the world, although Google is adding Kotlin as another option. For performance-intensive apps such as games, you have the option of writing in a “native” language such as C.
These apps run directly on the hardware of your Android device, as opposed to “regular” Java-based apps that run on the Dalvik Though it isn't strictly necessary to know it works in order to program in Java, it's still good to know because it may help you become a better programmer. Finally, there are ways of “wrapping up” web applications (using toolkits such as Microsoft’s Xamarin or Free courses are rarely as comprehensive and helpful - but we've found several React courses that are excellent and will get you started on the right foot.) for distribution as mobile apps that look “native.” While Choosing between an advanced IDE and a simpler text editor can be hard. We offer some insight to help you make that decision. Do handle some of the routine elements of programming, understand that the learning curve for this method is steep. Whatever language you choose, you’ll need to be versed in its basics. Investing this time up front is a drawback of this method, in the sense that you won’t be able to get into the development of your app right away.
But it’s an advantage in the long run, as the skills you learn can be applied elsewhere. After so many years, one would think that the mobile market is now saturated with every app imaginable to man - but that's not the case. There are plenty of niches that still need to., and you can develop for desktop and server-side applications (including web-based ones) in addition to Android apps.
Which Option is Best For Your Project? So which avenue is the “best?” This is too subjective to answer for everyone, but we can generalize it as follows. If you’re curious but just “playing around,” stick with the point-and-click app creators. They’ll help you scratch that creative itch without requiring any “coursework.” But if the idea of that coursework doesn’t frighten you, consider taking the longer path and learning a programming language. The investment will pay off in many other ways down the line. In addition, consider using both!
Point-and-click builders are an excellent way to quickly put together a prototype or “proof of concept.” Use them to work through some of the details (like layout and screen flow), as they are much quicker to shuffle around in a mouse-driven environment. Then re-implement them in Java if needed to take advantage of its flexibility. We’ll take precisely that approach in this guide. We will:. Prototype our application, a “scratchpad” that will store some text in a file for you, using MIT’s App Inventor.
Re-implement this in Java (with a little help from Google’s Android Studio IDE), then go on to extend the app to allow you to select from among multiple files, making it more of a “notepad.” Alright, enough talking. In the next section, we’ll get ready to code. Getting Ready to Create Your App Don’t dive right in just yet — first you need some knowledge and some software.
Knowledge You’ll Need Before we start installing some software, there’s some knowledge you should have before you start. First and foremost is, “What’s it supposed to do?” Waiting until you have a clear concept for your app before starting development may seem like a given — but you’d be surprised. So take some time to work through this concept, even jotting some notes on behavior and On a technical level, a modern website isn’t just one thing.
It’s a complex soup of interacting technologies, such as HTML (the markup you see on the page), JavaScript (the language running in your browser. Have a relatively complete picture of your app first. Next, look into what’s possible. For example, imagine the ideal picture of your app is something that lets you video-log your entire life for posterity.
You can create an app that will capture video. You can’t create one that will store every moment of your life on your device (insufficient storage). However, you can try to offload some of this storage to the cloud, although it will take time to develop, and that comes with its own limitations (what happens when you have no network access?). This is where you’ll examine some of the technical details and can inform decisions like whether you’ll code from scratch or not. Lastly, it’s worth knowing what’s out there already. If you’re just looking to learn or contribute to the community, is there an existing open source project like yours? Could you fork that project as a starting point?
Or even better, develop your enhancement and contribute it? If you’re looking to make money, what’s your competition like? If you write a simple alarm clock app and expect to make a million dollars off it, you had better bring something special to the table. As discussed, we’ll be building a simple scratchpad, which collects and holds some text you put into it.
And in doing so, we’ll be breaking the rules above, since there are many Android note-taking apps out there already, both Love open source software and want to take notes? We've got you covered. And If you want to take notes on your Android smartphone or tablet, you need one of these apps. But let’s pretend this will become a much more complex app later. You’ve got to start somewhere.
Now we’ll get some of the software you’ll need. Preparing to Develop with App Inventor You don’t need to install anything to use the App Inventor tool. It’s a web application, and you access it entirely through the browser. When you visit the site, you’ll see a button in the upper-right corner to Create apps! If you’re not currently logged into a Google account, clicking on this will direct you to a log-in page. Otherwise you should go directly to the App Inventor’s My projects page. At this point, consider where you want to test your app.
If you’re adventurous, you can test it out on your phone or tablet by installing. Then you’re all set for now — you’ll need a running project to actually see anything on your device, but we’ll get to that later. Alternatively, you can use the emulator to test your app on your computer. Download and install the emulator for your operating system from. The below image shows the app installing on Linux, but the appropriate version should install without issue on Windows or Mac as well.
You can start the emulator by running the “aiStarter” command. This starts Linux runs many applications 'in the background' that you might not even be aware of. Here's how to take control of them. That connects your (local) emulator to the (cloud-based) App Inventor. Windows systems will provide a shortcut for it, while it will start automatically for Mac users on login.
Linux users will need to run the following in a terminal: /usr/google/appinventor/commands-for-appinventor/aiStarter & Once it’s running, you can test the connection by clicking on the Emulator item in the Connect menu. If you see the emulator spin up (as shown in the image below), you’re good to go.
Installing Android Studio If you’re planning to develop some simple programs, App Inventor may be all you’ll ever need. But after playing around with it for a while, you may hit a wall, or you might know you’ll be using some features that App Inventor doesn’t support (like in-app billing). For this, you’ll need to have Android Studio installed.
Now the official development environment as sanctioned by Google, Android Studio is a version of the Java IDE from JetBrains. You can download a copy for your operating system from. Windows and Mac users can launch Modern operating systems provide you with easy methods to set up new applications. But what actually happens when you run that installer or issue that command?, respectively.
Linux users can use the ZIP file, unpack it wherever you like, and run Android Studio from there (Windows/Mac users can also do this). Otherwise, you can use Ubuntu Make to download and install the package for you. If you’re on the most recent LTS version (16.04 as of this writing), you’ll need to add the to your system to get access to Android Studio: sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make Then update your system with the following.
Sudo apt update Lastly, install Ubuntu Make with this command: sudo apt install umake Once installed, you can direct Ubuntu Make to install Android Studio for you with the following command: umake android android-studio After displaying the license agreement, it will begin downloading and installing the base application. Once it completes and you launch Android Studio, a wizard will lead you through another couple of steps.
First, you’ll get a choice on whether you want a “Standard” install, or something custom. Select the Standard install here, it will let you get started quicker. Then you’ll get a message that you need to download some additional components, and it’s probably going to take some time.
Once everything’s installed, you’ll get a small splash screen that let’s you create a new project, open an existing one, or access your settings. I know you’re ready to get your hands dirty. Without further ado, let’s build something.
Building a Simple Android Notepad Because we have (of course) sat and thought this through before just jumping in, we know our Android app will consist of two screens. One will allow the user to “edit now” or exit, and the other will do the actual editing. The first screen may seem useless, but it may come in handy later as we add features. The text captured on the “edit” screen will be stashed in a plain text file, because We use the word file interchangeably: music, image, spreadsheet, slideshow, and so on. But what makes a file a 'file,' anyway? Let's try and understand this fundamental part of computing. The following wireframes give us a good point of reference (and only took 5 minutes to whip up): In the next section, we’ll build it with MIT’s App Inventor.
Getting Started with MIT App Inventor The first step is to create a new project. Log into App Inventor, then click the Start new project button on the left (also available in the Projects menu). You’ll get a dialog to give it a name.
But now you’re dropped into App Inventor’s Designer view, and there’s a lot to take in. Let’s take a moment to look at each section. The title bar at the top shows your project name ( muoScratchpad); lets you add, remove, and switch between your app’s screens (e.g. Screen 1); and toggles between App Inventor’s Designer and Blocks views on the far right. The Palette on the left contains all the controls and widgets you’ll use. They’re divvied up into sections like User Interface and Storage; we’ll use both of these in our app.
We’ll see how the Palette holds different items in the Blocks view. The Viewer shows you what you’re building in WYSIWYG fashion. Components is a list of items that are part of the current screen. As you add buttons, text boxes, etc., they’ll show up here. Some “hidden” items, like references to files, will show here as well, even though they’re not actually part of the user interface.
The Media section lets you upload assets that you’ll use in your project, like images or sound clips. (We won’t need this one.). Finally, the Properties pane lets you configure the currently selected widget. For example, if you’re selecting an image widget, you can change its height and width.
Laying Out Your First Screen: “Main Screen” Let’s put the layout for the “main” screen together in Designer before moving on. Looking at the sketch, we’ll need a label for the app name, a line of help text, a button to move to the “edit” screen, and a button to exit. You can see the User Interface palette has all the items we need: two Labels, and two Buttons.
Drag these into a vertical column at the top of the screen. Next we’ll configure each one. For the labels, you can set elements like what the text should be, the background color, and alignment.
We’ll center both of our labels but set the background of the app name to black with white text. It’s time to see how it actually looks on a device. When you’re building things, do so in baby steps. I can’t emphasize this enough. Don’t build a big list of things into your app in one go, because if something breaks, it takes a long time to figure out why.
If you’re looking to test on a real phone, you can start up your AI2 Companion app and connect to App Inventor with either the QR code or the six-character code provided. To preview using the emulator, make sure you’ve started the aiStarter program described above, then select the Emulator item again from the Connect menu. Either way, after a short pause, you should see your app pup up, looking something like what you have in the Viewer (the actual layout may depend on the dimensions of your device and emulator). Since the title looks good, let’s change the text on the others as well and align them in the center (this is a property of the screen, AlignHorizontal, not the text/buttons). Now you can see one of the really cool aspects of App Inventor — all your changes are done in real time! You can see the text change, the buttons adjust their alignment, etc. Making it Functional Now that the layout’s done, let’s add some functionality.
Click the Blocks button in the upper left. You’ll see a similar layout as the Designer view, but you’ll have some different choices arranged in categories. These are programming concepts rather than interface controls, but like the other view, you’ll use drag-and-drop to put these together as part of your app. The left-hand Palette contains categories like Control, Text, and Variables in the “Built-in” category. The blocks in this category represent functions that will happen largely behind the scenes, such as the Math items that can perform calculations.
Below this is a list of the elements in your screen(s), and the blocks available here will affect those elements. For example, clicking on one of our Labels shows blocks that can change that label’s text, while the Buttons have blocks to define what happens when you click them. In addition to their category (represented by color), each block also has a shape that represents its purpose. These can be roughly divided as follows:. You can think of items with a big gap in middle, such as the “if-then” block shown above, as ones that handle events. When something takes place within the app, the other things inside that gap will run. Flat blocks with connectors are one of two things.
The first are statements, which are the equivalent of commands, the items that will fit in the flows above. In the example above, the make a list block is a statement, as is close application. The other option is expressions, which differ only slightly from statements. Where a statement might say “set this to ’42′”, an expression would be something like “add 22 to 20 and give me the result back.” In the above, is in list is an expression that will evaluate to either true or false. Expressions are also flat blocks, but they likely have a tab on the left side and a notch on the right.
Lastly, values include numbers (“17” and “42” above), strings of text (“Thing 1” and “Thing 2”), or true/false. They typically have a tab on the left only, as they’re something you provide to a statement or expression. You can certainly go through all the on App Inventor. However, it’s designed for you to just start clicking around and (literally) see what fits. On our initial page, we have two items that need attention (the Buttons), so let’s see what we can come up with.
One of these (Button2) will close the app when clicked. Since this is an interaction with the button. We can check for Button Blocks and find there’s one that starts with when Button2.click (or when Button 1 is clicked). This is exactly what we want, so we’ll drag this onto the Viewer. Now when it’s clicked, we want the app to close, which sounds like an overall app flow function.
Taking a peek in the Built-in Control section, we do indeed see a close application Block. And dragging it to the gap in the first block, it clicks into place. Now when you click the button, the app will close. Let’s try it in the emulator.
It shows us an error that closing the app isn’t supported in the development environment, but seeing this means it works! Building the Second Screen: Editor Screen Now let’s turn our attention to Button1.
This is supposed to open our editor, so we’d better make sure that editor exists! Let’s switch back to the Designer and create a new screen with the same Label as the first screen, a TextBox (set to “fill parent” for Width, 50% for Height, and with Multiline enabled) to hold our content, and another Button (labeled “ when Editor.initialize Block).
It should call File1.ReadFrom which points to our filename. We can capture the result of reading the text file using File when File1.GotText, assign that content to the TextBox using the TextBox set TextBox.Text to block, and hand it the get text value. Lastly, after saving, we want a click of Button1 to send us back to the main screen (a close screen Block).
Last step is to go back to the main screen and program the first button. We want it to send us to the Editor screen, which is a piece of cake with the Control open another screen block, specifying “Editor.” What Comes Next? Now that you’ve got something that works, what comes next? To enhance it of course! App Inventor gives you access to a wide array of Android functionality. Beyond the simple screens we just created, you can add capabilities including media playback, sending texts, or even a live web view to your app. One of the first improvements to come to mind is the ability to select from among multiple files.
But a quick reveals this requires some supreme hackery in App Inventor. If we want this feature, we’ll need to dig into Java and the Android Studio environment.
Development in Java with Android Studio The below sections will describe — at a very high-level — the development of our scratchpad app in Java. It’s worth repeating again: while it can pay great dividends down the road, learning Java and Android Studio requires a significant investment of time. So there won’t be as much explanation of what the code means below, nor should you worry much about it.
Teaching Java is beyond the scope of this article. What we will do is examine how close the Java code is to the things we’ve already built in App Inventor. Start by firing up Android Studio, and select the Start new Android Studio Project item. You’ll be led through a wizard asking a couple things. The first screen asks for a name for your app, your domain (this is important if you submit to the app store, but not if you’re just developing for yourself), and a directory for the project.
On the next screen, you’ll set If someone tells you they’re running Android, they’re not saying as much as you’d think. Unlike the major computer operating systems, Android is a broad OS that covers numerous versions and platforms. If you’d like. Selecting a more recent version will let you include the platform’s newer features, but might exclude some users whose devices aren’t current. This is a simple app, so we can stick with Ice Cream Sandwich.
Next we’ll select the default Activity for our app. Activities are a core concept in Android development, but for our purposes, we can define them as screens. Android Studio has a number you can select from, but we’ll just start with a blank one and build it ourselves.
The screen after that allows you to give it a name. Once the new project launches, take a moment to get acquainted with Android Studio. The top toolbar has buttons for a wide variety of functions. The one that’s most important for us is the Run button, which will build the app and launch it in the emulator. (Go ahead and try it, it’ll build just fine.) There are others such as Save and Find, but these work via the keyboard shortcuts we’re all used to (Ctrl+S and Ctrl+F, respectively). The left-hand Project pane shows the content of your project. You can double-click on these to open them for editing.
The center region is your editor. Depending on what precisely you’re editing, this may be text-based or graphical, as we’ll see in a moment. This may display other panes as well, such as a right-hand Properties pane (again, like App Inventor). The right and bottom borders have a selection of other tools that will pop up as panes when selected. There are things like a terminal for running command line programs and version control, but most of these aren’t important for a simple program.
Porting the Main Screen to Java We’ll start by re-building the scratchpad in Java. Looking at our previous app, we can see that for the first screen, we need a label and two buttons. In years past, creating a user interface on Android was a painstaking process involving hand-crafted XML. Nowadays, you do it graphically, just like in App Inventor. Each of our Activities will have a layout file (done in XML), and a code file (JAVA).
Click on the “mainactivity.xml” tab, and you’ll see the below (very Designer-like) screen. We can use it to drag-and-drop our controls: a TextView (like a Label) and two Buttons. Let’s wire up the Exit button. We need to create a Button in code as well as graphically, unlike App Inventor that handles that bookkeeping for us. But like AI, Android’s Java API uses the concept of an “onClickListner.” It reacts when a user clicks a button just like our old friend the “when Button1.click” block.
We’ll use the “finish” method so that when the user clicks, the app will exit (remember, try this in the emulator when you’re done). Adding the Editor Screen Now that we can close the app, we’ll re-trace our steps. Before wiring up the “Edit” Button, let’s make the Editor Activity (screen). Right-click in the Project pane and select New Activity Empty Activity and name it “EditorActivity” to create the new screen.
Then we create the layout of the Editor with an EditTextBox (where the text will go) and a Button. Adjust the Properties of each to your liking. Now switch to the EditorActivity.java file.
We’ll code up some similar functions to what we did in App Inventor. One will create the file to store our text if it doesn’t exist, or read its content if it does.
A couple of lines will create the EditTextBox and load our text into it. Lastly, a bit more code will create the Button and its onClickListener (which will save the text to the file, then close the Activity). Now when we run it in the emulator, we’ll see the following:. Prior to running, there is no folder at “/storage/emulated/0/Android/data/your domain and project name/files,” which is the standard directory for app-specific data. On first run, the Main screen will appear as expected. Still no directory as above, nor our scratchpad file. On clicking the Edit button, the directory is created, as is the file.
On clicking Save, any text entered will be saved to the file. You can confirm by opening the file in a text editor. On clicking Edit again, you’ll see the previous content. Changing it and clicking Save will store it, and clicking Edit again will recall it.
And so forth. On clicking Exit, the app will finish. Enhancing the App: Select Your Storage File Now we have a working version of our original App Inventor scratchpad. But we ported it to Java in order to enhance it. Let’s include the ability to select from among multiple files in that standard directory. Once we do this, we’ll really make this more of a notepad than just a scratchpad, so we’ll create a copy of the current project.
We used an Android Intent to call our Editor Activity from the main one, but they’re also a convenient way to call other applications. By adding a couple of lines of code, our Intent will send a request for There are a bunch of file management and file exploring apps out there for Android, but these are the best. This means we can remove a good portion of the code checking for an creating the file, since the Intent will only allow us to browse/select one that actually exists. In the end, our Editor Activity stays exactly the same. Getting our Intent to give us back a String (Java text object) that we can pack into our Intent was a challenge. Fortunately, when it comes to programming questions, the internet is your friend. A gives us a couple of options, including code we can paste into our app.
Code courtesy of And with this small change and a bit of borrowed code, we can use a file browser/manager application on the device to select the file for storing our content. Now that we’re in “enhancement mode,” it’s easy to come up with a couple more useful improvements:. We can choose from among existing files, but for the moment, we removed our facility to create them. We’ll need a feature for the user to provide a file name, then create and select that file.
It might be useful to make our app respond to “Share” reques.
System RequirementsTo use App Inventor, your computer must meet the following system requirements:Computer and operating system. Macintosh (with Intel processor): Mac OS X 10.5, 10.6+. Windows: Windows XP, Windows Vista, Windows 7+.
GNU/Linux: Ubuntu 8+, Debian 5+ (Note: GNU/Linux live development is only supported for WiFi connections between computer and Android device.) Browser. Mozilla Firefox 3.6 or higher (Note: If you are using Firefox with the NoScript extension, you'll need to turn the extension off.
See the note on the.). Apple Safari 5.0 or higher. Google Chrome 4.0 or higher. App Inventor does not support Microsoft Internet Explorer. Windows users should use Chrome or Firefox Phone or Tablet (or use the on-screen emulator). Android Operating System 2.3 ('Gingerbread') or higher Whichever model you have, your phone must have an SD card (physical or virtual) installed, or else the phone won't work with App Inventor. Most modern Android phones have virtual SD cards, so this is an issue only for older phones.App Inventor also works with many other Android phones, including models from HTC, Samsung, and Dell, but in many cases you will need to download and install additional software from the manufacturer.
You can find details for a few of these models in that table at the bottom of the page for. Even if your phone is not listed there, it is still likely to work with App Inventor. Consult the under 'Getting set up and connecting your phone' for advice from others who may be using the same phone.