Why Teams call analytics are critical to your entire business
Learning Android Part 2/6
1. The Greenoid’s GuideTo Building Android™ Apps [Part–2/6] Android & the Green Robot are a trademark of Google Inc. http://greenoid.blogspot.com (Oct 2010)
3. What Goes into an App? Activities Each activity is an Android version of a basic UI block Content Provider You write content providers to share data of any form residing on the device with other applications Services If you want your code to run always, without any UI elements, services are the answer Intents A notification mechanism for system events like hardware changes, incoming sms … you can also create your own intents to notify others. http://greenoid.blogspot.com (Oct 2010)
4. Inside An Android Project The Manifest File A declaration of all components inside your application, like activities, services, user permissions, SDK version, and optional libraries in use. XML Layouts You can specify an UI layout in XML and attach it to an activity, giving you freedom to modify the UI without worrying about code. R.java An auto-generated file that connects resources like the XML layout definitions to java code. http://greenoid.blogspot.com (Oct 2010)
5. Writing an App Thankfully when you click on New Project in Eclipse the basic skeleton and Manifest file are auto-magically created. The skeleton public class MyActivityextends Activity { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); TextViewtv = new TextView(this); setContentView(tv); } } http://greenoid.blogspot.com (Oct 2010)
6. The Skeleton Explained MyActivity extends Activity Think of the Activity like a high level UI container Public void onCreate(Bundle icicle) Invoked when the activity is created, you might want to create some basic UI widget like a button or TextView here setContentView( TextView ) Since the Activity is a high-level UI container, you will have to call setContentView(button/label) to add your widget to the container If you created a button You will have to do btn.setOnClickListener() to receive events And implement public void onClick(View v) to handle it http://greenoid.blogspot.com (Oct 2010)
7. The Widget Palette All Widgets extend View TextView - A basic label widget Button - Well, it’s a button ImageView, ImageButton: support for images CheckBox, RadioButton, RadioGroupare a few common UI widgets http://greenoid.blogspot.com (Oct 2010)
8. Sample Code For the Lazy package com.droid.clockwork; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import java.util.Date; public class MainClock extends Activity { /** Called when the activity is first created. */ public void onCreate(Bundle icicle) { super.onCreate(icicle); TextViewtv = new TextView(this); tv.setText("The Time Now Is: "+new Date().toString()); setContentView(tv); } } http://greenoid.blogspot.com (Oct 2010)