2014年5月6日 星期二

Android App Fundamentals

Android App Components
http://developer.android.com/guide/components/fundamentals.htmlActivity : App compose of one and more activity, each activity has UI to interact with user.Service: background processContent Provider: Read/Write interface for accessing data stored in SQLite/ Web/ System dataBroadcast Receiver: to receive system broadcast.

App components are declared in manifest file: "AndroidManifest.xmlThe manifest does a number of things in addition to declaring the app's components, such as:
  • Identify any user permissions the app requires, such as Internet access or read-access to the user's contacts.
  • Declare the minimum API Level required by the app, based on which APIs the app uses.
  • Declare hardware and software features used or required by the app, such as a camera, bluetooth services, or a multitouch screen.
  • API libraries the app needs to be linked against (other than the Android framework APIs), such as the Google Maps library.
  • And more

Activities, services, and content providers that you include in your source but do not declare in the manifest are not visible to the system

View and ViewGroup
View objects are usually UI widgets such as buttons or text fields andViewGroup objects are invisible view containers that define how the child views are laid out, such as in a grid or a vertical list.

View and ViewGroup are defined in fragment_main.xml file in the res/layout/ directory.

Text 
Text are defined in a string resource file at res/values/strings.xml

Intent
An Intent is an object that provides runtime binding between separate components (such as two activities). The Intent represents an app’s "intent to do something." You can use intents for a wide variety of tasks, but most often they’re used to start another activity.

Intent intent = new Intent(this, DisplayMessageActivity.class);
The constructor used here takes two parameters:
  • Context as its first parameter (this is used because the Activity class is a subclass of Context)
  • The Class of the app component to which the system should deliver the Intent (in this case, the activity that should be started)
Every Activity is invoked by an Intent, regardless of how the user navigated there. You can get the Intentthat started your activity by calling getIntent() and retrieve the data contained within it.

Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

沒有留言:

張貼留言