android development: build android app from scratch

78
Android Development: Build Android App from Scratch Taufan Erfiyanto, ST. A one day workshop of Android Development at Phetchaburi Rajabhat University, Thailand. In collaboration with Gunadarma University and Phetchaburi Rajabhat University.

Upload: taufan-erfiyanto

Post on 15-Jul-2015

350 views

Category:

Mobile


4 download

TRANSCRIPT

Page 1: Android Development: Build Android App from Scratch

Android Development: Build Android App from Scratch

Taufan Erfiyanto, ST.

A one day workshop of Android Development at Phetchaburi Rajabhat University, Thailand. In collaboration with Gunadarma University and Phetchaburi Rajabhat University.

Page 2: Android Development: Build Android App from Scratch

Founder of pongodev.com, mobile application developer and the man who responsible to deliver the app with beautiful user interface and insure that it generates many download with marketing strategy.

About

[email protected]

twitter.com/taufan20

linkedin.com/in/taufan20

Page 3: Android Development: Build Android App from Scratch

portfolio

Page 4: Android Development: Build Android App from Scratch

Crowdfunding mobile-based application that allows users raise funds for humanity and environmental activities. Donation can be done via smartphone credit and transfer.

http://donasia.org

Page 5: Android Development: Build Android App from Scratch

What do you know about Android?

Page 6: Android Development: Build Android App from Scratch

1 billion Android population.

Horace dediu

Page 7: Android Development: Build Android App from Scratch

1.43 million apps on Google Play in 2014.

appFigures

Page 8: Android Development: Build Android App from Scratch

268 billion times downloads and generate revenue $77

billion in 2017.

Gartner

Page 9: Android Development: Build Android App from Scratch

Available in all devices, smartphone, watch, tv,

and car.

Page 10: Android Development: Build Android App from Scratch

Android Development Tools

Page 11: Android Development: Build Android App from Scratch

1. Java Development Kitdownload: bit.ly/JDKandroid

Page 12: Android Development: Build Android App from Scratch

2. Android Studio and SDK Toolsdownload: bit.ly/AnStudio

Page 13: Android Development: Build Android App from Scratch

Creating New Project

Page 14: Android Development: Build Android App from Scratch

1. Select Start a new Android Studio Project on Welcome window.

Page 15: Android Development: Build Android App from Scratch

2. Type application name and company domain.

Page 16: Android Development: Build Android App from Scratch

3. Select Device Type and Minimum SDK.

Page 17: Android Development: Build Android App from Scratch

4. Select Blank Activity in Activity type.

Page 18: Android Development: Build Android App from Scratch

5. Name your first activity and layout file.

Page 19: Android Development: Build Android App from Scratch

Understand the Project Structure

Page 20: Android Development: Build Android App from Scratch

1. Android project consist of manifest, java, res, and Gradle directories.

Page 21: Android Development: Build Android App from Scratch

2. Activity works as a page in application. Located in java directory.

Page 22: Android Development: Build Android App from Scratch

3. The first method that will be executed when app run is onCreate().

Page 23: Android Development: Build Android App from Scratch

4. Every activity has layout file as its user interface. located in res/layout directory.

Page 24: Android Development: Build Android App from Scratch

5. To connect layout and activity, setContentView() must be defined.

Page 25: Android Development: Build Android App from Scratch

6. Every activity created must be registered to AndroidManifest.xml.

Page 26: Android Development: Build Android App from Scratch

Creating Android Emulator

Page 27: Android Development: Build Android App from Scratch

1. Open AVD Manager via Tools > Android.

Page 28: Android Development: Build Android App from Scratch

2. Select Create Virtual Device… button.

Page 29: Android Development: Build Android App from Scratch

3. Select device type and screen resolution.

Page 30: Android Development: Build Android App from Scratch

4. Select Android version.

Page 31: Android Development: Build Android App from Scratch

5. Type emulator name.

Page 32: Android Development: Build Android App from Scratch

6. Select the emulator name and click Launch icon.

Page 33: Android Development: Build Android App from Scratch

Running Android Project on Emulator

Page 34: Android Development: Build Android App from Scratch

1. Select Run > Run ‘app’.

Page 35: Android Development: Build Android App from Scratch

2. Select Launch emulator and emulator name. Or select Choose a running device if you have

running emulator.

Page 36: Android Development: Build Android App from Scratch

Running Android Project on Android Device

Page 37: Android Development: Build Android App from Scratch

1. On Android device, select Settings > Developer Options. Enable USB Debugging.

Note: Android 4.2 and newer go to Settings > About phone and tap Build number seven times.

Page 38: Android Development: Build Android App from Scratch

2. Connect Android device to the computer via usb cable.

Page 39: Android Development: Build Android App from Scratch

3. Select Run > Run ‘app’.

Page 40: Android Development: Build Android App from Scratch

2. Select Choose a running device and device name.

Note: some device require a driver from its factory to be installed on the computer.

Page 41: Android Development: Build Android App from Scratch

Creating User Interface

Page 42: Android Development: Build Android App from Scratch

1. Open your xml layout file in layout directory.

Page 43: Android Development: Build Android App from Scratch

2. Drag widget on Palette section to device screen on the right side.

Page 44: Android Development: Build Android App from Scratch

3. Configure widget properties via properties window on the right bottom corner of the window.

Note: important properties are id, layout_width, and layout_height.

Page 45: Android Development: Build Android App from Scratch

Manipulating Widget

Page 46: Android Development: Build Android App from Scratch

1. Open activity file that use activity_main.xml layout in java directory.

Page 47: Android Development: Build Android App from Scratch

2. Create objects of the widgets in activity file that you want to manipulate.

Page 48: Android Development: Build Android App from Scratch

3. Connect the objects with widget id in xml layout inside onCreate() method.

Page 49: Android Development: Build Android App from Scratch

4. Add event handling to button object.

Page 50: Android Development: Build Android App from Scratch

5. manipulate your widget when button click inside onClick() method.

Page 51: Android Development: Build Android App from Scratch

Creating To Do List App

Page 52: Android Development: Build Android App from Scratch

1. Modify the user interface as seen above. Consist of EditText, Button, and ListView.

Page 53: Android Development: Build Android App from Scratch

2. Create objects of EditText, Button, and ListView in activity file.

Page 54: Android Development: Build Android App from Scratch

3. Connect the objects with widget id in xml layout.

Page 55: Android Development: Build Android App from Scratch

4. Create ArrayAdapter object and ArrayList variable above onCreate() method.

Page 56: Android Development: Build Android App from Scratch

5. Define adapter parameter and set it to list object using setAdapter().

Page 57: Android Development: Build Android App from Scratch

6. Add button event handling to add data to the list.

Page 58: Android Development: Build Android App from Scratch

7. Run the project to see the result.

Page 59: Android Development: Build Android App from Scratch

Integrating SQLite Database to Android

Project

Page 60: Android Development: Build Android App from Scratch

1. Create new directory under app/src/main directory via window explorer. name it as assets.

Page 61: Android Development: Build Android App from Scratch

2. Create database to store data inside assets directory using sqlitebrowser.

Note: database of to do list app can be download at bit.ly/dbTodo and sqlitebrowser can be download at bit.ly/sqliteAndroid.

Page 62: Android Development: Build Android App from Scratch

3. Create new java file inside app/java/package.name.

Page 63: Android Development: Build Android App from Scratch

4. Name it as DBHelper.Note: Download DBHelper.java file at bit.ly/DBHelper

and copy the code to your DBHelper.java.

Page 64: Android Development: Build Android App from Scratch

5. Define database path, database name, table name and fields.

Note: SQLiteOpenHelper is used for creating, opening, and upgrading database. SQLiteDatabase is used for communicating data of database.

Page 65: Android Development: Build Android App from Scratch

6. Create object of DBHelper class and ArrayList variable in Activity file.

Page 66: Android Development: Build Android App from Scratch

7. Connect dbhelper object with it class and call createDataBase() and openDataBase() method.

Page 67: Android Development: Build Android App from Scratch

8. Create displayData() method before closing bracket to display data from database with

getAllNotes() method.

Page 68: Android Development: Build Android App from Scratch

9. And call displayData() method after openDataBase() method.

Page 69: Android Development: Build Android App from Scratch

10. Call addNote() and displayData() method inside button event handling to add data to

databse and display them after added.

Page 70: Android Development: Build Android App from Scratch

11. Run the project to see the result.

Page 71: Android Development: Build Android App from Scratch

12. Add new arraylist variable to store note id.

Page 72: Android Development: Build Android App from Scratch

13. Do not forget to clear ids and add ids in displayData() method.

Page 73: Android Development: Build Android App from Scratch

14. Create list event handling to delete note with item on list click.

Page 74: Android Development: Build Android App from Scratch

15. Call removeNote() method to remove data from database and displayData() method to re-

display data on the list.

Page 75: Android Development: Build Android App from Scratch

16. Run the project again to see the result.

Page 76: Android Development: Build Android App from Scratch

What do you need to know next to mastering Android development?

Page 77: Android Development: Build Android App from Scratch

FragmentsMaterial Design

Hardware Integration

Multiple Screen Support

Connect to Web Services

Page 78: Android Development: Build Android App from Scratch

–Joel Spolsky, Stack Exchange

Nothing works better than just improving your product.