Suggest title that better reflects content ←Older revision Revision as of 23:35, 8 June 2019 (2 intermediate revisions by the sam...

Write an Android App

Suggest title that better reflects content

←Older revision Revision as of 23:35, 8 June 2019
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Liquid error: wrong number of arguments (1 for 2)Android is a cheap, high-tech and fast growing operating system. Anyone can start as developer as it is open source . There are about 800 million android users and it has been used with many electronic devices. Thus everyone feels a need or desire to get a special app  for various reasons.
+
Liquid error: wrong number of arguments (1 for 2)Android Studio is the official IDE for Android apps. It doesn't cost anything and supports the Java and Kotlin programming languages. It gives you great control over what your app does. So why not program your app in it?
  +
This article expects you to know the basics of Java, if you don't, please look at How To [[Write Your First Program in Java]] for an introduction.
 
[[Category:Android Applications]]
 
[[Category:Android Applications]]
 
[[Category:Articles in Quality Review]]
 
[[Category:Articles in Quality Review]]
  +
== Steps ==
  +
===Install Android Studio===
  +
#Download Android Studio. It is found on the website [http://bit.ly/1rQt9Qs http://bit.ly/1rQt9Qs]. Make sure to get the version for your system. Since the file is about 1GB big, this will take some time. You can do something else meanwhile, as long as you don't do anything that interrupts the download (like closing the browser or switching off the computer).[[Image:Android studio download page.png|center]]
  +
#Install the dependencies. If you have a 64-bit Linux computer (skip this step if you don't), you will have to install some additional packages.<ref>http://bit.ly/2EZZpcU> On a system that uses apt, enter into the command line: . If your system uses yum, enter the following instead:
  +
#Extract the archive. Skip this step if you downloaded an or file. Otherwise, change to the directory into which you downloaded the archive. Then, either right-click on it in the file manager and select the "Extract here" option. or enter into the command line (replace "downloadName" with the name of the file you just downloaded).[[Image:Android studio extract archive.png|center]]
  +
#Launch Android Studio. If you downloaded an or file, just double-click on it. If you downloaded and extracted an archive, change to the subdirectory "bin" of the directory with the extracted files (usually "android-studio"). This is done by typing . Run the file "studio.sh" by typing .[[Image:Android studio launch.png|center]]
  +
#Decide whether to import settings. If this is your first time using Android Studio, select "No". If you used it before and want to have the previous settings, select "Yes" and specify where you saved them.
  +
#Decide whether to send usage data to Google. This is a personal decision and won't change anything in the installation or programming process.
  +
#Wait until a window appears. It will be called "Android Studio Setup Wizard". Click on to proceed.
  +
#Decide whether to do a standard or custom install. If this is your first time using Android Studio and/or you don't have special requirements, you should select "Standard".
  +
#Select dark or light theme. The dark theme is called "Darcula", while light one is simply called "Light". This changes what Android Studio looks like, but won't have any other effect on the interface. So select the one you prefer.[[Image:Android studio setup dark light theme.png|center]]
  +
#Review the settings. Check whether it will install how you want. Then, click on to start downloading the components.[[Image:Android studio setup review settings.png|center]]
  +
#Wait until the components are downloaded. This will take some time, and you can do something else meanwhile. When they are downloaded, click on .
  +
===Start a new project===
  +
#Click on "Start a new Android Studio project". It is found in the window labelled "Welcome to Android Studio", directly under the Android Studio logo. If you don't see such a window, check whether that window is hidden by other windows you have opened.[[Image:Android studio new project start.png|center]]
  +
#Select an activity. That, with some buttons and forms you add, will be the first thing a user sees when they open the app. For learning how to make apps, you should select "Empty Activity". When you have figured out app programming, you can use the additional features the other activities provide.[[Image:Android studio select activity.png|center]]
  +
#Configure your project. Enter a name for your app. It should be short and descriptive so that you see immediatly what the app is for. Select Java as the language. For a simple app, you should choose a platform that is supported by most devices, even if it is older. Click on and wait while Gradle sets up your project.[[Image:Android studio configure project.png|center]]
  +
===Program the app===
  +
#Understand what you want to do. Think about what input the user will give, how you will process it (you can improvise during programming, but you should have an outline of how it should work), how you will display the output to the user. This example shows how to create an app where the user can enter two numbers and the sum is displayed.
  +
#Open the translations editor. It is a good practice to only use strings from the translation ressources even if you aren't translating the app. Switch to the tab "activity_main.xml". Then click on the menu that shows a globe and the text . It is located under the tabs, in the middle. Click on the appearing option .[[Image:Android studio open translation editor.png]]
  +
#Add some text. You will have to explain to the user what they're supposed to do with the app. To add a string, press on the button in the upper left corner of the translation editor. Insert a short key (this is like a variable name, for example "main_instruction") and the full English text (for example "Enter two numbers to add:"). If you want, you can add a locale using the button that depicts a globe with a + sign on it, and then translate all the text to that locale.[[Image:Android studio add string to resources.png|center]]
  +
#Close the translation editor and switch to "activity_main.xml". You will see an empty screen with a textbox displaying the text "Hello World!" in the middle. For now, this is a pretty useless interface.
  +
#Replace "Hello World!". Click on the textbox. Select the input labeled "text" on the right side and replace "Hello world!" with "@string/main_instruction" (or whatever you called the key you created). The textbox will now display the text you entered for that key. Drag it further up so that you have space for other elements below it. When it is at the correct position, right-click on the entry of "TextView" in the menu that displays all items on the screen. Select → . If this moves the textbox to an inacceptable position, move it back to where it was and repeat. Select → to center the textbox horizontally.[[Image:Android studio textbox customize.png|center]]
  +
#Place two numeric inputs on the screen. These are found under → . Change the IDs to something you can remember, like "number1" and "number2". Constrain and center like the textbox. You can ignore the warning about missing "autoFillHints" attribute.[[Image:Android studio add number input.png|center]]
  +
#Place a button on the screen. Normal buttons are found under → . Add a string in the translation editor with the key "text_add" and "Add" as text. Go back to "activity_main.xml" and replace the text "Button" with "@string/text_add". Give the button a descriptive ID, like "buttonAdd". Constrain and center as before.[[Image:Android studio finished layout.png|center]]
  +
#Add two other textboxes. First, add the two translation strings. One should be "Result:" and the other one should be "not calculated yet". Then, add the textboxes from → . Replace the strings with the ones you added. Give textbox that displays "not calculated yet" an ID like "resultOutput". Constrain these textboxes to parent top and to parent start.[[Image:Android studio layout finished with textboxes.png|center]]
  +
#Switch to "mainActivity.java". This is the file that contains the app code.
  +
#Declare the necessary variables. You will need to get the user input, to react when the user presses a button, and to change the "not calculated yet" textbox to the result of the calculation. To do this, the program needs to "see" the items on the screen. You should declare them as because you will never change them directly, only their attributes. So type inside the onCreate() function, after the call to setContentView(): <source lang="java">final EditText num1 = findViewById(R.id.number1);</source><source lang="java">final EditText num2 = findViewById(R.id.number2);</source><source lang="java">final Button buttonAdd = findViewById(R.id.buttonAdd);</source><source lang="java">final TextView resultOut = findViewById(R.id.resultOut);</source>[[Image:Android studio coding variable declarations.png|center]]
  +
#Create a click listener. This is the function that is called when the user clicks on the button. To add one, type:<source lang="java">buttonAdd.setOnClickListener(new View.OnClickListener() {</source><source lang="java">  @Override</source><source lang="java">  public void onClick(View v) {</source><source lang="java">  }</source><source lang="java">});</source>[[Image:Android studio coding set click listener.png|center]]
  +
#Add code into the click listener. You want to get the user's inputs, convert them to integers, add them together, and change the text of the "not calculated yet" textbox to the result. Following code does that:<source lang="java">int sum = Integer.parseInt(num1.getText().toString()) + Integer.parseInt(num2.getText().toString());</source><source lang="java">outResult.setText(Integer.toString(sum));</source>[[Image:Android studio coding functions in onclicklistener.png|center]]
  +
===Test the app===
  +
#Build the APK. Click on → → . Wait while the APK is built. Then, click on the "locate" link in the appearing pop-up in the lower right corner. This will open the folder with the APK in the file manager.[[Image:Android studio build apk.png|center]]
  +
#[[Connect|Connect-Android-Phone-to-Computer]] your Android smartphone to your computer using the USB / microUSB transfer cable.
  +
#Copy the APK onto your smartphone. To avoid making a mess on the smartphone, either create a new directory for your APKs (for now it is only one, but if you continue developing, you will soon have many) or use the Downloads directory. Don't copy the file, just ignore it.
  +
#Find the APK on the smartphone. Open the file manager. If it isn't in the recent downloads or in the APKs section, search for it.[[Image:Android studio smartphone find apk.png|center]]
  +
#Tap on the APK. This will ask you whether to install it. Tap and wait for the installation.
  +
#Open the app on the smartphone. It will have a white Android logo behind a dark blue-green background as icon.[[Image:Android studio app icon.png|center]]
  +
#Check whether the app functions as expected.[[Image:Android studio check app function.png|center]]
   
== Steps ==
+
== Tips ==
#  Learn Java. Java is the basis for Android development. Thus strong knowledge base for programming Java is needed.
+
*You have to allow installing apps from external sources in the settings of the smartphone to be able to install and test your app on it.
#  Download Android SDK and IDE (eclipse or Android Studio).<ref>http://bit.ly/1EdqvpM.html?hl=sk </ref>
+
*You can delete the APK after installation. You can always build a new one on your computer if you need it again.
#  Setup and install other required tools. Get the latest tools, versions, and plugins, and also update your Java.
+
*If you create something you think will be useful to others, you can your app on some distribution platform like Google Play. But while you are still learning, you as well keep your programming experiments to yourself, having only saved them locally on your smartphone and computer.
#  Explore the SDK.
+
 
#  Get basic idea of activity, fragments, and other android coding basics. Try YouTube and other online resources for app developers.
+
== Warnings ==
#  Start your new Android app / project . Name it.
+
*Typing any commands mentioned in this article into the Windows command line doesn't work. Use the other methods specified instead.
#  Import required packages supported in Android. See Android reference for details.
+
*Only install Android Studio when you have a good internet connection. If it is interrupted often during the installation process, unexpected problems can occur.
#  Get to know the development environment. Try a simple code like the "hello world" program. Play with the visual editor.
+
 
#  Run it. Try and test the AVD (Emulator).
+
== Things You'll Need ==
# Start your personal coding. Run and test on emulator and then on a device.
+
*Computer with Windows, Linux or Mac OS X
#  Enjoy and have fun. When all is said and done, you may love to sell and publish your app on internet or in the Google Play Store.
+
*Internet connection (for installation)
  +
*Smartphone with Android
  +
*USB to microUSB transfer cable
   
 
== References ==
 
== References ==
   
  +
  +
__PARTS__


from wikiHow - Recent Changes [en] http://bit.ly/2EZ5kz9
via IFTTT