190 likes | 204 Views
Class Business. Android Introduction. Android is an operating system that runs on mobile platforms “smartphones” & tablets Cars Watches Cameras Based on Linux Open source, free. History. Android, Inc founded in 2003, financed by Google Google bought the company in 2005
E N D
Android Introduction • Android is an operating system that runs on mobile platforms • “smartphones” & tablets • Cars • Watches • Cameras • Based on Linux • Open source, free
History • Android, Inc founded in 2003, financed by Google • Google bought the company in 2005 • Android release Android in 2007 • First handset in 2008 • Releases are named after desserts/snacks(current is “Marshmallow” – Android 6.0.1)
Issues on Android Platforms • Platforms are battery powered, restricted in CPU and memory • Screens are small compared to desktops • Policies • When an app is no longer in use, the system will suspend it in memory (consume no resources) • When memory is low, the system will kill apps and processes that have been inactive for a while
Environment • Android Development Kit is free • Hooks into Eclipse or Android Studio • Emulators are useful
User Interface • The UI for an Android app is built using a hierarchy of View and ViewGroup objects. • View objects are usually UI widgets such as buttons or textfields • ViewGroup objects are invisible view containers that define how the child views are laid out, such as in a grid or a vertical list.
Assumed Methods • Android programming is very object oriented • There are lots of assumed methods initially defined as empty that govern app behavior.
Activity • An Activity is the main object in an Android app. • Lifecycle:
XML • HTML-like syntax that is used for many things, especially specification languages • HTML is actually a specialized XML • Tag-based language<blah> … </blah>
Example: activity_main <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout>
AndroidManifest.xml • Basic app specification file • Contains info on: • Permissions • Version minimums • Icons
Event Programming in Android • Same idea, different methods, clunky implementation • Might want to take special actions to make the code look nice
Listeners • OnClickListener is the analog to ActionListener in Java • Others: • OnLongClickListener • KeyListener • Many built-in listeners just need methods defined
Example (note pattern) LinearLayout container = (LinearLayout) dialog.findViewById(R.id.new_class_dialog_button_container); EditText et = (EditText) dialog.findViewById(R.id.new_class_name); et.setText(""); et = (EditText) dialog.findViewById(R.id.new_class_nickname); et.setText(""); Button button = (Button) container.findViewById(R.id.create_new_button); button.setOnClickListener(new createNewClassDialogAction(dialog)); button = (Button) container.findViewById(R.id.cancel_new_button); button.setOnClickListener(new cancelDialogAction(dialog));
Stupid: showDialog • When a dialog needs to be display, you would call “showDialog(DIALOGNUMBER)” • Then define “onCreateDialog(int dialognum)” • Amounts to a big if…then…else… combinationReally bad code