Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mobile Computing With Android ACST 4550 Intro to Android, Part 1

Similar presentations


Presentation on theme: "Mobile Computing With Android ACST 4550 Intro to Android, Part 1"— Presentation transcript:

1 Mobile Computing With Android ACST 4550 Intro to Android, Part 1

2 Brief Android History The version history of the Android mobile operating system began with the release of the Android beta in November The first commercial version, Android 1.0, was released in September Android is under ongoing development by Google and the Open Handset Alliance, and has seen a number of updates to its base operating system since its original release. These updates typically fix bugs and add new features.

3 Brief Android History Since April 2009, Android versions have been developed under desert codenames and released in alphabetical order: Cupcake, Donut, Eclair, Froyo, Gingerbread, Honeycomb, Ice Cream Sandwich, Jelly Bean and KitKat. As of 2013, over 500 million active devices use the Android OS worldwide. In 2014 that number passed 1 billion active devices. As of 2015, Android has the largest installed base of all operating systems.

4 Brief Android History

5 Brief Android History

6 Getting Started (1) Need to install Java Development Kit (JDK) to write Java (and Android) programs Do not install Java Runtime Environment (JRE); JDK and JRE are different! Can download the JDK for your OS at Alternatively, for OS X, Linux: OS X: Open /Applications/Utilities/Terminal.app Type javac at command line Install Java when prompt appears Linux: Type sudo apt–get install default–jdk at command line (Debian, Ubuntu) Other distributions: consult distribution’s documentation

7 Getting Started (2) After installing JDK, download Android SDK from Simplest: download and install Android Studio bundle (including Android SDK) for your OS Alternatives: Download/install Android Developer Tools from this site (based on Eclipse) Install Android SDK tools by themselves, then install ADT for Eclipse separately (from this site) We’ll use Android Studio with SDK included (easy)

8 Getting Started (3) You should see this:

9 Getting Started (4) Strongly recommend testing with real Android device Android emulator: very slow Install USB drivers for your Android device! Bring up the Android SDK Manager Recommended: Install Android 4.03, 5.01 and 6.0 APIs 15, 21 and 23 Now you’re ready for Android development!

10 Android Highlights (1) Android apps execute on Dalvik VM, a “clean-room” implementation of JVM Dalvik optimized for efficient execution Dalvik: register-based VM, unlike Oracle’s stack-based JVM Java .class bytecode translated to Dalvik EXecutable (DEX) bytecode, which Dalvik interprets

11 Android Highlights (2) Android apps written in Java 5
Actually, a Java dialect (Apache Harmony) Everything we’ve learned still holds Apps use four main components: Activity: A “single screen” that’s visible to user Service: Long-running background “part” of app (not separate process or thread) ContentProvider: Manages app data (usually stored in database) and data access for queries BroadcastReceiver: Component that listens for particular Android system “events”, e.g., “found wireless device”, and responds accordingly

12 App Manifest Every Android app must include an AndroidManifest.xml file describing functionality The manifest specifies: App’s Activities, Services, etc. Permissions requested by app Minimum API required Hardware features required, e.g., camera with autofocus External libraries to which app is linked, e.g., Google Maps library

13 Activity Lifecycle Activity: key building block of Android apps Extend Activity class, override onCreate(), onPause(), onResume() methods Dalvik VM can stop any Activity without warning, so saving state is important! Activities need to be “responsive”, otherwise Android shows user “App Not Responsive” warning: Place lengthy operations in Runnable Threads, AsyncTasks Source: [12]

14 App Creation Checklist
If you own an Android device: Ensure drivers are installed Enable developer options on device under Settings, specifically USB Debugging Android 4.2+: Go to Settings→About phone, press Build number 7 times to enable developer options For Android Studio: Under File→Settings→Appearance, enable “Show tool window bars”; the Android view shows LogCat, devices Programs should log states via android.util.Log’s Log.d(APP_TAG_STR, “debug”), where APP_TAG_STR is a final String tag denoting your app Other commands: Log.e() (error); Log.i() (info); Log.w() (warning); Log.v() (verbose) – same parameters

15 Creating Android App (1)
Creating Android app project in Android Studio: Go to File→New Project Enter app, project name Choose package name using “reverse URL” notation, e.g., edu.osu.myapp Select APIs for app, then click Next

16 Creating Android App (2)
Determine what kind of Activity to create; then click Next We’ll choose a Blank Activity for simplicity Enter information about your Activity, then click Finish This creates a “Hello World” app

17 Deploying the App Two choices for deployment:
Real Android device Android virtual device Plug in your real device; otherwise, create an Android virtual device Emulator is slow. Try Intel accelerated version, or perhaps Run the app: press “Run” button in toolbar

18 Underlying Source Code
src/…/MainActivity.java package edu.kennesaw.helloworld; import ... public class MainActivity extends AppCompatActivity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; }

19 Underlying Source Code (cont.)
src/…/MainActivity.java @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }

20 Underlying GUI Code res/layout/activity_main.xml
<android.support.design.widget.CoordinatorLayout xmlns:android=" xmlns:app=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="edu.kennesaw.helloworld.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_height="wrap_content" android:layout_width="match_parent" <android.support.v7.widget.Toolbar android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" /> </android.support.design.widget.AppBarLayout> <include <android.support.design.widget.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" /> </android.support.design.widget.CoordinatorLayout>

21 The App Manifest AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android=" package="edu.kennesaw.helloworld" > <application android:allowBackup="true" android:supportsRtl="true" > <activity android:name=".MainActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

22 Java API Class Libraries
Standard Java API: Android Java API:


Download ppt "Mobile Computing With Android ACST 4550 Intro to Android, Part 1"

Similar presentations


Ads by Google