Sams Teach Yourself Android™Application Development in 24 Hours 0321673352Copyright ©2010 Lauren Darcey and Shane Conder FIGURE 5.6 Simplified Android platform architecture from a securi
Trang 1Android GUI Project
John Hurley
CS 454
Trang 3Android 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 developer’s 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 It’s not clear to me how this works
• Docs say it does not necessarily improve performance
Trang 4Sams Teach Yourself Android™Application Development in 24 Hours (0321673352)
Copyright ©2010 Lauren Darcey and Shane Conder
FIGURE 5.6 Simplified Android platform architecture from a security perspective.
Trang 5Android Development
other parts of the Java platform are missing
libraries are not included
Trang 6Android Development
• Standard development environment is Eclipse + Android
Development Tools plugin + Android SDK
• Development requires either an Android OS device or an
emulator
• Emulator has limitations:
• Performance is poor
• Camera, etc., simulated using your computer’s hardware
• No real phone calls or texts
• GPS data, battery readings, etc must be simulated
• Real device is affected by specific hardware and software
configuration
Trang 7Android vs Other 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:
•I had Java backend code ready to go for a first project
•Interesting platform:
• Familiar programming environment
• Currently the market leader
• Broad market, unlike more focused iOS, Blackberry, and
(Palm) webOS
• Development tools are open source and are free even for
commercial use, unlike Visual Studio
Trang 8Android App vs Mobile- Optimized RIA
• Android Flash plugins available; Silverlight coming soon
• Could develop in JavaScript and/or HTML5
• 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
• Probably better performance; one layer less
Trang 9Android Apps: Marketing
• Usually market apps through Android App Market
• There are other markets, also
• App store will dominate the market due to access through
built in app
• Can set up for download directly on a website
• User must agree to “install apps from unknown sources”
Trang 10Android Apps: Marketing
• Revenue from app sales prices and/or advertising
• Conventional wisdom is that iOS users will pay for apps,
but Android users won’t
• 57% of Android App Store apps are free, vs 28% for Apple
App Store
• Android Market takes 30% commission
• Any purchase model other than one-time purchase must be
homegrown, using Paypal or similar service
• PPC ads
• My guess is that response to these is extremely low
• Probably need to be very aggressive with banner ads
• Sell to companies?
Trang 11Android Deployment
then downloaded to device and installed
various other files
hardware access info, minimum OS release info, etc
Trang 12Android UI
• Activity: single screen with a UI, somewhat analogous to
XAML / code behind pattern in NET
• Email app might have one activity that shows a list of
new emails, another activity to compose an email, and another activity for reading emails
• Implement by subclassing Activity class
• View: drawable object
• Android UI View ≠ MVC View
• UI contains a hierarchy of Views
• View is a class, subclassed by the drawable objects in
the UI
Trang 13Android UI
a different application
user interaction with an activity
Trang 14Android UI
Trang 15public 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);
}
}
Trang 16Manual 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"
<string name="hello">Hello Again, CS454!</string>
<string name="app_name">CS454 AndroidDemo</string>
</resources>
Trang 17public class AndroidDemo extends Activity {
/** Called when the activity is first created */
Trang 18What’s R?
/* AUTO-GENERATED FILE DO NOT MODIFY This class was automatically generated by the
* aapt tool from the resource data it found It should not be modified by hand */
package cs454.demo;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int textview=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
Trang 19UI With GUI Builder
Trang 20Android Event Handlers
From the code file for the activity:
Button ok = (Button) findViewById(R.id.button1);
Trang 21Sams Teach Yourself Android™Application Development in 24 Hours (0321673352)
Copyright ©2010 Lauren Darcey and Shane Conder
FIGURE 3.2 Important callback methods of the activity life cycle.
Trang 22APIs for Android built-ins
Trang 23Demo
Trang 24My Project
• Goats and Tigers is a board game, which we implemented in
Java in CS 460 last term
• The objective in CS460 was to implement the minmax / alpha
beta pruning algorithm for the automatic player, not to
create a good UI
• My existing interface shows an ASCII art picture of the board
and provides a JOptionPane menu of available moves
• I will develop an Android UI and use my existing backend
code as much as possible
Trang 25• Conder and Darcey, Sams Teach Yourself Android Application
Development in 24 Hours, Sams, 2010