Android GUI Project: John Hurley CS 454
Android GUI Project: John Hurley CS 454
John Hurley
CS 454
Android
1.
2.
3.
4.
5.
Android Basics
Android Development
Android UI
Hello, World
My Project
Android Basics
Open source OS
Uses Linux kernel
Optimized for limited-resource environment
Apps typically written in Java
Apps run on the Dalvik Virtual Machine
Not a JVM, but works similarly from
developers point of view
Usually one app per DVM
Each DVM runs under Linux as a separate
user
App permissions set at install time
Possible to use C or C++ compiled to machine
code, but still runs on VM. Its not clear to me
how this works.
Android Development
Well-defined framework for app
development
Apps are typically coded using Java
syntax, but other parts of the Java
platform are missing
Some standard Java SE or ME APIs and
class libraries are not included
I will give examples when I find out!
Android Development
Performance is poor
Camera, etc., simulated using your computers
hardware
No real phone calls or texts
GPS data, battery readings, etc. must be
simulated
Mobile OS
I was able to choose what kind of smart phone to
get according to which platform I wanted to use to
try mobile development
Android:
WWW App
Easier for users to run; no need to install
For a paid app, avoid the 30% App Store
commission
Easier to write cross-platform apps
Android Apps
Fewer security hurdles
Use APIs for access to built in GPS, camera,
etc.
Android Deployment
Apps are packaged in .apk format,
variant of .jar, then downloaded to
device and installed
.apks contain .dex files (bytecode),
manifest and various other files
Manifest contains security and link
info, hardware access info, minimum
OS release info, etc.
Android UI
Android UI
Service: background operation
play music in the background while the
user is in a different application
fetch data over the network without
blocking user interaction with an
activity
Content Provider: DB or other data access
Broadcast Receiver: responds to system
messages
Battery low
Android UI
UI construction can be done in three
ways:
Programmatic, like hand-coded Java
desktop GUI construction
Declarative hand-written, like Java web
UI construction
XML
Programmatic UI
package cs454.demo;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
public class AndroidDemo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Activity is a subclass of context, so the TextView takes this as a parameter
TextView tv = new TextView(this);
tv.setText("Hello, CS454");
setContentView(tv);
}
}
Manual Declarative UI
main.xml Layout File:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello"/>
strings.xml resource file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello Again, CS454!</string>
<string name="app_name">CS454 AndroidDemo</string>
</resources>
Manual Declarative UI
Java class:
package cs454.demo;
import android.app.Activity;
import android.os.Bundle;
public class AndroidDemo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
Whats R?
Handlers
From the code file for the activity:
Button ok = (Button) findViewById(R.id.button1);
ok.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
CharSequence s = et.getText();
tv.setText("Welcome, " + s);
}
});
Demo
My Project
References
http://www.ibm.com/developerworks/opensource/library/osandroid-devel/
http://
developer.android.com/resources/browser.html?tag=tutorial
Conder and Darcey, Android Wireless Application
Development, Addison-Wesley, 2010
Conder and Darcey, Sams Teach Yourself Android
Application Development in 24 Hours, Sams, 2010