19
‘HELLO WORLD’ ON ANDROID

‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

  • Upload
    others

  • View
    43

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

‘HELLO WORLD’ ON ANDROID

Page 2: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Download and Install Android Studio

• Download the latest version of Android Studio from here: https://developer.android.com/studio/.

• Create your virtual devices: – ToolsAVD ManagerCreate Virtual Device

Page 3: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

References• Set up Android Studio

– https://sites.google.com/site/mobilesecuritylabware/home/appendix/setup/1-choice-two--set-up-android-studio

• Create Hello World App– https://sites.google.com/site/mobilesecuritylabwa

re/home/appendix/setup/build-a-android-project-by-android-studio

– www.youtube.com/watch?v=bsB2JUgXeGs

Page 4: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Create a new Android Project• Open File->New->Android project

– Application name

– Company domain

– Project location

Page 5: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Hello World Project

• Target Android Devices

Page 6: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Hello World Project

• Add an Activity

Page 7: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Hello World Project

• Customize the activity

Page 8: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Hello World Project

8

• manifests– AndroidManifest.xml: application description file

• java: source folder

– HelloWorldActivity.java• res: resource files and resource description files

– layout: layout files• Activity_hello_world.xml

– values:• colors.xml

• Strings.xml

• Styles.xml

• Gradle Scripts: Gradle an open source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven for declaring the project configuration.

Page 9: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Say Hello World

9

• modify HelloWorld.java

Page 10: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Run Hello World

Page 11: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Behind HelloWorld #1

• res/values, contains string declarations or other values(e.g.:colors) of the app

– string.xml, contains string resources

referenced in

activity_hello_world.xml

define new string

resources

Page 12: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Behind HelloWorld #2

• AndroidManifest.xml describe the application

– declare app’s name, version, icon, permission, etc…

– declare the application's components: activity, service ,receiver or provider

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.jhe4.helloworld">

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

<activity android:name=".HelloWorldActivity">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

Page 13: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Core Components-Activity #1• Basically, An activity presents a visual user interface

for one focused endeavor the user can undertake

• An application might consist of just one activity or several, each Activity is derived from android.app.Activityand should be declared in AndroidManifest.xml file

• Each activity is given a default window to draw in, the window may be full screen or smaller and on top of other window

• The visual content of the window is provided by a hierarchy of views — objects derived from the base View class

• Activity.setContentView() method is used to set a certain hierarchy of view objects

Page 14: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Core Components-Activity #2• Activities are activated by asynchronous messages called

intents

– An intent is an Intent object that holds the content of the message

– The action being requested or the URI of the data to act on

• The <intent-filter> label in AndroidManifest.xmlfile specifies the Intent that can start the Activity

– declares the main activity, it will be started automatically when the app starts

• An activity is launched (or given something new to do) by passing an Intent object to Context.startActivity() or Activity.startActivityForResult()

Page 15: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Activity

lifecycle

Page 16: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Other Core Components

• Service– A service doesn't have a visual user interface, runs in

the background for a period of time

• Broadcast receivers– a component that does nothing but receive and react

to broadcast announcements

• Content providers– A content provider makes a specific set of the

application's data available to other applications.

– The data can be stored in the file system, in an SQLite database, or in any other manner that makes sense

Page 17: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Beyond HelloWorld #1

• Build up an app that you can input your

greetings and display your greetings

– Input: EditText

– Display: TextView

– Of course, we have to add an button

• Edit res/layout/activity_hello_world.xml file

to add these components

– each has an android:id property, used to

reference it in code

Page 18: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Beyond HelloWorld #2• modify HelloWorld.java

– firstly get the references declared in main.xml

– then add event response for Button

Page 19: ‘HELLO WORLD’ ON ANDROIDksuweb.kennesaw.edu/.../Slides/01HelloWorldApp.pdf · • Gradle Scripts: Gradle an open source build ... android.app.Activity and should be declared in

Useful Materials

Android Official Site

• http://www.android.com

Android SDK, Tutorial, Concepts and API docs

• http://androidappdocs.appspot.com/index.html

Android Development Community

• http://www.anddev.org/

30 Days Android Apps Development

• http://bakhtiyor.com/category/30-days-of-android-apps/