- 浏览: 2551102 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Android Introduce(I)concepts and NoteBook example
1. Open Handset Alliance
Consist of the system
View----->lists, grids, text boxes, buttons, web browser
Content Providers-----> access to other applications(for example, contact database)
Resource Manager----->
Notification Manager----->
Activity Manager ----->
Application lib
System C -----> libc for embedded linux
Media lib -----> MPEG4, H.264, MP3, AAC, AMR, JPG, PNG
Surface Manager ---->
LibWebCore -----> Web browser engine
SGL ------> 2D
3D libraries ----> 3D
FreeType -------> bitmap and vector
SQLite -----> database engine
Dalvik ----> .dex
2. Build Android Envirenment
3. Application Analytic
Activity
Sometimes one activity means one screen. One activity is one class which extends from base activity
(android.app.Activity). There are data send/receive between 2 screens/activities.
Intent
Action and Data.
Action: MAIN, VIEW, PICK, EDIT
Intent ------> IntentFilter ------> IntentReceiver
IntentReceiver
Service
Without activity, it will run in the system. Context.startService().
Content Provider
Share the data among in different applications
4. Dalvik Virtual Machine
android.app ---------->runtime envirement
android.content--------->access and publish the data
android.database------>db
android.graphics--------> diagram lib, point, line and others, draw them on screen
android.location -------->
android.media -----------> music, video
android.net ---------------->
android.os -----------------> system service, message transfer, IPC
android.opengl ---------> OpenGL tool
android.provider -------> content provider
android.telephony ----->
android.view --------------> look and feel
android.util ----------------> date and time util
android.webkit ---------->
android.widget ----------> UI
Java file ------> Class -------> Dex ------> apk
5. Android Source Codes HelloActivity
AndroidManifest.xml configuration file
layout/main.xml setContentView(R.layout.main);
values/strings.xml android:text="@string/hello"
R.java gen from the xml files under res
content of main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
</LinearLayout>
steps in java sources:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//create the UI with codes
//TextView tv = new TextView(this);
//tv.setText("This is test about say hello to Carl!");
//setContentView(tv);
//create the UI with the help of XML file
setContentView(R.layout.main);
}
6. Priority of threads
front thread
Activities are using.
visual thread
for example, pause activity
service thread
backend thread
unvisual activity
empty thread
7. Get more steps on the HelloActivity, try to write a Note book
get the sample codes from here
http://www.chinaup.org/docs/intro/codelab/NotepadCodeLab.zip
Reading the code of Notepadv1
public class Notepadv1 extends ListActivity {
public void onCreate(Bundle savedInstanceState); //load the activity, show the page
public boolean onCreateOptionsMenu(Menu menu); //draw the menu
public boolean onOptionsItemSelected(MenuItem item);// menu was clicked
}
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS notes");
onCreate(db);
}
}
Reading the code of Notepadv2
public class Notepadv2 extends ListActivity {
//use intent to communicate with another activity
private void createNote() {
Intent i = new Intent(this, NoteEdit.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
//send extra message to another activity
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Cursor c = mNotesCursor;
c.moveToPosition(position);
Intent i = new Intent(this, NoteEdit.class);
i.putExtra(NotesDbAdapter.KEY_ROWID, id);
i.putExtra(NotesDbAdapter.KEY_TITLE, c.getString(
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
i.putExtra(NotesDbAdapter.KEY_BODY, c.getString(
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
startActivityForResult(i, ACTIVITY_EDIT);
}
//get the message back from Bundle
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
switch(requestCode) {
case ACTIVITY_CREATE:
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
String body = extras.getString(NotesDbAdapter.KEY_BODY);
mDbHelper.createNote(title, body);
fillData();
break;
case ACTIVITY_EDIT:
Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
if (rowId != null) {
String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE);
String editBody = extras.getString(NotesDbAdapter.KEY_BODY);
mDbHelper.updateNote(rowId, editTitle, editBody);
}
fillData();
break;
}
}
}
public class NoteEdit extends Activity {
protected void onCreate(Bundle savedInstanceState) {
...snip...
mTitleText = (EditText) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);
Button confirmButton = (Button) findViewById(R.id.confirm);
mRowId = null;
Bundle extras = getIntent().getExtras();
if (extras != null) {
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
String body = extras.getString(NotesDbAdapter.KEY_BODY);
mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
if (title != null) {
mTitleText.setText(title);
}
if (body != null) {
mBodyText.setText(body);
}
}
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putString(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString());
bundle.putString(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString());
if (mRowId != null) {
bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
}
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}
});
}
}
Reading the code of Notepadv3
Only send the id of the data, move the createNote database functions to NoteEdit.java
public class Notepadv3 extends ListActivity {
...snip...
private void createNote() {
Intent i = new Intent(this, NoteEdit.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, NoteEdit.class);
i.putExtra(NotesDbAdapter.KEY_ROWID, id);
startActivityForResult(i, ACTIVITY_EDIT);
}
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
fillData();
}
...snip...
}
public class NoteEdit extends Activity {
...snip...
mTitleText = (EditText) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);
Button confirmButton = (Button) findViewById(R.id.confirm);
mRowId = savedInstanceState != null ? savedInstanceState.getLong(NotesDbAdapter.KEY_ROWID)
: null;
if (mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID) : null;
}
populateFields();
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
setResult(RESULT_OK);
finish();
}
});
}
private void populateFields() {
if (mRowId != null) {
Cursor note = mDbHelper.fetchNote(mRowId);
startManagingCursor(note);
mTitleText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
mBodyText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
}
}
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
}
protected void onPause() {
super.onPause();
saveState();
}
protected void onResume() {
super.onResume();
populateFields();
}
...snip...
}
1. Open Handset Alliance
Consist of the system
View----->lists, grids, text boxes, buttons, web browser
Content Providers-----> access to other applications(for example, contact database)
Resource Manager----->
Notification Manager----->
Activity Manager ----->
Application lib
System C -----> libc for embedded linux
Media lib -----> MPEG4, H.264, MP3, AAC, AMR, JPG, PNG
Surface Manager ---->
LibWebCore -----> Web browser engine
SGL ------> 2D
3D libraries ----> 3D
FreeType -------> bitmap and vector
SQLite -----> database engine
Dalvik ----> .dex
2. Build Android Envirenment
3. Application Analytic
Activity
Sometimes one activity means one screen. One activity is one class which extends from base activity
(android.app.Activity). There are data send/receive between 2 screens/activities.
Intent
Action and Data.
Action: MAIN, VIEW, PICK, EDIT
Intent ------> IntentFilter ------> IntentReceiver
IntentReceiver
Service
Without activity, it will run in the system. Context.startService().
Content Provider
Share the data among in different applications
4. Dalvik Virtual Machine
android.app ---------->runtime envirement
android.content--------->access and publish the data
android.database------>db
android.graphics--------> diagram lib, point, line and others, draw them on screen
android.location -------->
android.media -----------> music, video
android.net ---------------->
android.os -----------------> system service, message transfer, IPC
android.opengl ---------> OpenGL tool
android.provider -------> content provider
android.telephony ----->
android.view --------------> look and feel
android.util ----------------> date and time util
android.webkit ---------->
android.widget ----------> UI
Java file ------> Class -------> Dex ------> apk
5. Android Source Codes HelloActivity
AndroidManifest.xml configuration file
layout/main.xml setContentView(R.layout.main);
values/strings.xml android:text="@string/hello"
R.java gen from the xml files under res
content of main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
</LinearLayout>
steps in java sources:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//create the UI with codes
//TextView tv = new TextView(this);
//tv.setText("This is test about say hello to Carl!");
//setContentView(tv);
//create the UI with the help of XML file
setContentView(R.layout.main);
}
6. Priority of threads
front thread
Activities are using.
visual thread
for example, pause activity
service thread
backend thread
unvisual activity
empty thread
7. Get more steps on the HelloActivity, try to write a Note book
get the sample codes from here
http://www.chinaup.org/docs/intro/codelab/NotepadCodeLab.zip
Reading the code of Notepadv1
public class Notepadv1 extends ListActivity {
public void onCreate(Bundle savedInstanceState); //load the activity, show the page
public boolean onCreateOptionsMenu(Menu menu); //draw the menu
public boolean onOptionsItemSelected(MenuItem item);// menu was clicked
}
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS notes");
onCreate(db);
}
}
Reading the code of Notepadv2
public class Notepadv2 extends ListActivity {
//use intent to communicate with another activity
private void createNote() {
Intent i = new Intent(this, NoteEdit.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
//send extra message to another activity
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Cursor c = mNotesCursor;
c.moveToPosition(position);
Intent i = new Intent(this, NoteEdit.class);
i.putExtra(NotesDbAdapter.KEY_ROWID, id);
i.putExtra(NotesDbAdapter.KEY_TITLE, c.getString(
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
i.putExtra(NotesDbAdapter.KEY_BODY, c.getString(
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
startActivityForResult(i, ACTIVITY_EDIT);
}
//get the message back from Bundle
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
switch(requestCode) {
case ACTIVITY_CREATE:
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
String body = extras.getString(NotesDbAdapter.KEY_BODY);
mDbHelper.createNote(title, body);
fillData();
break;
case ACTIVITY_EDIT:
Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
if (rowId != null) {
String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE);
String editBody = extras.getString(NotesDbAdapter.KEY_BODY);
mDbHelper.updateNote(rowId, editTitle, editBody);
}
fillData();
break;
}
}
}
public class NoteEdit extends Activity {
protected void onCreate(Bundle savedInstanceState) {
...snip...
mTitleText = (EditText) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);
Button confirmButton = (Button) findViewById(R.id.confirm);
mRowId = null;
Bundle extras = getIntent().getExtras();
if (extras != null) {
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
String body = extras.getString(NotesDbAdapter.KEY_BODY);
mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
if (title != null) {
mTitleText.setText(title);
}
if (body != null) {
mBodyText.setText(body);
}
}
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putString(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString());
bundle.putString(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString());
if (mRowId != null) {
bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
}
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}
});
}
}
Reading the code of Notepadv3
Only send the id of the data, move the createNote database functions to NoteEdit.java
public class Notepadv3 extends ListActivity {
...snip...
private void createNote() {
Intent i = new Intent(this, NoteEdit.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, NoteEdit.class);
i.putExtra(NotesDbAdapter.KEY_ROWID, id);
startActivityForResult(i, ACTIVITY_EDIT);
}
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
fillData();
}
...snip...
}
public class NoteEdit extends Activity {
...snip...
mTitleText = (EditText) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);
Button confirmButton = (Button) findViewById(R.id.confirm);
mRowId = savedInstanceState != null ? savedInstanceState.getLong(NotesDbAdapter.KEY_ROWID)
: null;
if (mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID) : null;
}
populateFields();
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
setResult(RESULT_OK);
finish();
}
});
}
private void populateFields() {
if (mRowId != null) {
Cursor note = mDbHelper.fetchNote(mRowId);
startManagingCursor(note);
mTitleText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
mBodyText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
}
}
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
}
protected void onPause() {
super.onPause();
saveState();
}
protected void onResume() {
super.onResume();
populateFields();
}
...snip...
}
发表评论
-
ionic UI(4)ionic2 framework - basic and components and native
2016-03-24 02:33 1261ionic UI(4)ionic2 framework - b ... -
ionic UI(3)TypeScript - handbook
2016-03-22 23:21 634ionic UI(3)TypeScript - handboo ... -
ionic UI(2)ionic2 framework - TypeScript - tutorial
2016-03-22 06:52 1656ionic UI(2)ionic2 framework - T ... -
Parse and Heroku Service(3)Parse Server and Parse Dashboard
2016-03-22 06:30 967Parse and Heroku Service(3)Pars ... -
Parse and Heroku Service(2)Mail Templates and Push Notification
2016-03-22 02:45 583Parse and Heroku Service(2)Mail ... -
ionic UI(1)Introduction
2016-03-19 03:18 723ionic UI(1)Introduction 1 Inst ... -
Parse and Heroku Service(1)Heroku Installation and Play
2016-03-19 00:13 824Parse and Heroic Service(1)Hero ... -
Hybrid(5)Customize Meteor Directly Google Login
2015-09-01 02:33 910Hybrid(5)Customize Meteor Direc ... -
Hybrid(4)Favorite Places - Google Login
2015-09-01 02:02 1341Hybrid(4)Favorite Places - Goog ... -
Hybrid(3)More Meteor Example - Social
2015-08-11 05:04 756Hybrid(3)More Meteor Example - ... -
Hybrid(2)meteor Running Android and iOS
2015-07-28 23:59 1049Hybrid(2)meteor Running Android ... -
Create the Google Play Account
2015-07-18 06:42 1101Create the Google Play Account ... -
Secure REST API and Mobile(1)Document Read and Understand OAUTH2
2015-07-14 00:36 764Secure REST API and Mobile(1)Do ... -
Screen Size and Web Design
2015-07-11 01:11 725Screen Size and Web Design iPh ... -
Hybrid(1)ionic Cordova meteor
2015-06-25 05:49 471Hybrid(1)ionic Cordova meteor ... -
Android Fire Project(1)Recall Env and Knowledge
2015-02-11 12:28 686Android Fire Project(1)Recall ... -
Android Content Framework(1)Concept
2014-06-14 13:54 1080Android Content Framework(1)Con ... -
Feel Android Studio(1)Install and Update Android Studio
2014-04-11 03:12 2029Feel Android Studio(1)Install a ... -
IOS7 App Development Essentials(2)iBeacon
2014-03-05 05:55 890IOS7 App Development Essentials ... -
IOS7 App Development Essentials(1) Persistent Store
2014-03-05 05:54 1327IOS7 App Development Essentials ...
相关推荐
Several example projects within this book introduce you to using the GPIO, SPI, and I2C hardware interfaces of the BeagleBone Black. You'll create Android apps that communicate directly with actual ...
Programming Concepts in C++ is one in a series of books that introduce the basic concepts of computer programming, using a selected programming language. Other books in the series use languages like ...
Lastly, we'll introduce a set of Android tools that help you debug and profile your apps. Unit 2, Project Framework, discusses the storyline and framework of your first game Raccoon Rob. You'll be ...
### Decompiling Android: Key Insights and Concepts The document "Decompiling Android.pdf" delves into the complex world of decompiling on the Android platform, a topic of significant importance for ...
标题与描述中的核心知识点是关于Android开放手机联盟(Open Handset Alliance,简称OHA)的介绍,以及Android操作系统的概述。以下是对这些知识点的详细解释: ### Android开放手机联盟(OHA) Android开放手机...
This book is for Android developers who want to learn how to build multithreaded and reliable Android applications using high-level and advanced asynchronous techniques and concepts. What You Will ...
里面介绍了PD方案和在实际中应用说明,及遇到的问题,解决方法,里面有市场上主流IC的介绍,供各工程技术人员学习和参考。
This book aims to introduce readers to the fundamental concepts of general-purpose GPU programming using CUDA. The book's target audience includes programmers, researchers, and students interested in...
Android 7.0 Audio Framework 介绍 Android 7.0 Audio Framework 是 Android 操作系统中负责音频播放和录音功能的框架。该框架主要由三部分组成:Audio 的 JAVA 程序部分、Audio 的 JNI 部分和 Audio 的客户端部分...
If you are looking to automate Excel routine tasks, this book will progressively introduce you to programming concepts via numerous, illustrated, hands-on exercises. Includes a comprehensive disc ...
As each language is presented, the authors introduce new concepts as they appear, and revisit familiar ones, comparing their implementation with those from languages seen in prior chapters....
Green Coffee Green Coffee is a library that allows you to run your acceptance tests written in Gherkin in your Android instrumentation tests using the step ... And I introduce an invalid password
We introduce theAndroid Security Framework (ASF),a generic, extensible security framework for Android that enables the development and integration of a wide spectrum of security models in form of code...
Android RIL,全称为Radio Interface Layer,是Android操作系统中至关重要的一个组件,它充当着操作系统与无线通信硬件之间的桥梁。RIL负责处理所有与移动网络相关的底层通信,包括蜂窝数据、电话呼叫、短信服务以及...
team introduce.key
programming concepts and techniques. “Fundamentals-first” means that students learn fundamental programming concepts like selection statements, loops, and functions, before moving into defining ...
Brocade Product introduce and Hand on Training....