NIIT 安卓复习提纲+答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
一、基础:
1.安卓核心组件有哪些?
Activities、Services、Content providers、Broadcast receives
2.安卓 key features 有哪些?
Integrated browser、SQLite、Media support、Wireless services、DVM、Application framework、Rich development environment
3.安卓用什么数据库?
SQLite Database
4.几个流行的移动平台各自的 IDE 是什么?
1.Symbian(Qt Creator)
2.Android(Eclipse\Android Studio)
3.BlackBerry(The BlackBerry
Java Development Environment (JDE) ) 4.IOS(Xode) 5.Windows(Visual Studio)
5.R.java 是什么文件?干什么用的?在什么地方?
R.java is an index database file,store the ID of all the resource in app.
R.java located in /gen directory.
6.安卓平台架构分为几层?各是什么?
Android platform has a four-layered architecture:
Linux kernel、Libraries and Android runtime、Application framework、Applications
7.创建一个 UI 并运行之,有哪几个步骤?
a.Create a new Android project;
b. Design the UI ,you can use the controls in toolbox or coding in the layout.xml file;
c. Associate the UI with the activity;
d. Register the activity.
8.Intent 有几个组件?各是干什么用的?哪些组件是必须存在的,哪些是可选的,在Manifest 中
intent filter 是如何声明的?
Component name: Specify the name of the component that should handle the intent.
Action: Specify the action that needs to be performed
Data: Specifies the data to operate on .
Category: Specifies the behaviour of the target application component.
Extras: Contains extras information in the form of key-value pairs that must delivered to the components that handle the intent.
Flags: Includes flags that control various aspects related to activating a new component.
必须存在:Action
可选:Data、Category
In the Manifest file ,intent filter was defined as following:
Intent filter was declared in the form of tag<intent-filter> </intent-filter> and the tag was contained in the tag <application> </application>.
9.Activity的生命周期有哪些状态?状态转换时调用的方法各是什么?
Running、Paused、Stopped
10.同一个应用之间Activity互相调用要用什么Intent(隐式、显式?还是什么?)?
Use Explicit Intent.
1)Explicit Intent(指定接收者): Explicit Intent specify the name of the target component in order to activate that component .Such intents are used to start an activity or a service within the same application.
2)I mplicit Intent(不指定接收者): Implicit intents are used to activate the components of other applications. Implicit intents do not specify the target component by their name ,components advertise their capability to do a job by using a intent filers.
11.什么是Dalvik Virtual Machine?
DVM is a running-environment for Android application which interpreted Android byte codes at runtime..
12.安卓日志类 Log 有几种常用方法?各用于什么输出什么信息?哪些信息只应该在开发的时候才允许输出?
The Log class provides five methods,such as :
1.Log.e (): used to log errors. For example:try-catch block
2.Log.w (): used to log warnings.
3.Log.i (): used to log informational messages such as information related to state of
activities or services.
4.Log.d (): used to log debug messages,which can be used for debugging an application.
5.Log.v (): used to log verbose messages.
开发时输出:debug message and verbose message
二、核心机制:
1.什么是Content Provider
Content Provider can help application access storage locations,it also can store and
retrieve data making the data can be accessed to all applications.
2.什么是Broadcast Receiver
A broadcast receiver is a component of an application that responds to system-wide broadcast announcements.
3.什么是Intent
Intents are messages used to activate application components such
as ,activities,services,and broadcast receivers.
4.什么是Service,Service有哪些状态?
An Android service is an application component that does not provide any user
interface and keeps running in the background.
started and bound
5.安卓的资源有哪些类型?各放在什么位置?
Animation Resources 文件位置:res/anim/ or res/drawable
Color State List Resource 文件位置:res/color/
Drawable Resource 文件位置:res/drawable/
Layout Resource 文件位置:res/layout/
Menu Resource 文件位置:res/menu/
String Resource 文件位置:res/values/
Style Resource 文件位置:res/values/
More Resource Types 文件位置:res/values/
6.IPC是什么意思?和Intent有什么关系?
IPC(Inter-process Communication)
Intent is one of type IPC.
7.Broadcast有哪几种?区别?
Normal Broadcasts 、Ordered Broadcasts
Normal Broadcasts: broadcasts are sent to all interested receivers at the same time and the receivers run in an undefined order often at the same time.
Ordered Broadcasts: broadcast are sent to all interested receives in a proper order. 8.Ordered broadcast如何决定接收者的顺序?
Ordered broadcast decide the receive order by receiver’s priority.
9.安卓中的 Permissions,包括怎么向系统申请权限,怎么用权限保护自己等
If an application needs to access a restricted resource/component, it need to declare the required permission in the application’s manifest file by using the <uses-permission> tag; If you want to protect an application ,you can use the <permission> tag in your manifest file;
三、IO:
1.安卓原生支持几种IO机制?各自有什么特点?
1.SQLite Database: SQLite is that an open-source ,standard-compliant,lightweight and single-tier RDBMS.
2.Internal storage: The data be stored is very small and can be stored in files instead of a database;
3..External storage: It provide a large capacity that allow user to store large files;
4.Shared Preference: It used to customize applications in the form of a framework that allows you to retrieve persistent key-value pairs of built-in data types;
5.remote location: It can extracts current data(updated frequently) from the Web and sends
it to the application that requests the data;
2.安卓原生的content provider有哪些?
1.Browser、
2.Contacts、
3.Call log 、
4.Media store、
5.Setting
3.如何创建一个content provider?
1)Create a custom content provider;
2)Specify the URI of a content provider;
3)Implement query handling methods;
4)Access the data exposed by a content provider;
5)Handle requests for the MIME type of data;
6)Register a custom content provider.
4.安卓下访问一个文件,要写到文件最后,要用什么模式打开文件?
Use the File Creation Modes:MODE_APPEND
The mode creates a file if it does not exist.However,if it exists,any content added to the file is appended at the end of the existing file.
5.判断SD卡是否可用,用什么方法?
If(Environment.MEDIA_MOUNTED.equals(Enviroment.getExternalStorageState()))
6.Shared Preferences 是什么?有什么用?
1)Shared preferences are a lightweight mechanism used to store key-value pairs of
primitive data types.
2)Shared Preference are an ideal preferences.They are most frequently used to persist data
across user sessions and to share settings between application components.
7.要从远端URL播放多媒体文件用什么stream?
HTTP stream
8.创建一个安卓数据库都有哪些途径?
1) Creating a database programmatically;
2)Creating a database through shell commands.
四、UI:
1.安卓有哪些常见的布局管理器(Layout)?各有什么特点?
1.Linear layout: The linear layout allows you to arranges widgets in a single row;
2.Table layout: This layout arranges its child views in rows and columns;
3.Frame layout: This layout is used to add views in a stack format, one item over another;
4.Relative layout: In this layout, views are positions relatively to their neighbors or
parents.
5.Absolute layout: This layout allow you to specify the exact position of views on a layout.
2.按下button,被调用的回调函数是什么?
onClick()
3.安卓内建的theme有哪些?
1)Theme.Black
2)Theme.Light
3)Theme.Translucent
4)Theme.Dialog
5)Theme.Holo
4.各种对话框共同的父类是是什么?
The Dialog class acts as the base class of for creating all dialogs.
5.View类是什么?起什么作用?
Answer: The view class is the basic building block of an Android application’s UI and the parent of all widgets. Views are graphical representations of components and enable event handling on components.
6.Options Menu是什么?Context Menu是什么?
1)Options Menu is the primary collection of menu items for an activity, which
appears when the user presses the MENU button on the emulator/device.
2)Context Menu is a floating list of menu items that appears when user touches and holds
a view that is registered to provide a context menu.
7.Android 原生支持哪几种 Dialog?
1)AlertDialog
2)ProcessDialog
3)DatePickerDialog
4)TimePickerDialog
8.安卓画图相关的主要有哪3个类?各自作用?
1)Canvas: A Canvas represents a surface where you can draw shapes and images;
2)Paint: The Paint class in Android provides information about the style and color for drawing
symbols, text, and graphics;
3)Bitmap :A bitmap image uses pixels to create graphics.
9.复合控件(compound views)是什么?
Compound views refer to combining multiple views into a logical group of items that can be treated as a single view.
五、Tools:
1.ADB是什么?ADB工具一般放在什么位置?
ADB(Android Debug Bridge)is a debug tool ,which is a versatile command line tool that allows to communicate with an emulator instance or connect Android-enabled mobile device.
一般放在:<sdk>/platform-tools/folder
2.安卓开发环境包括哪些东西?
The Android development environment include IDE and Android SDK.
3.安卓应用程序有哪些类型?
Foreground app、Background app、Intermittent app 、Small component
4.<uses-permission> 和 <uses-feature> 是什么?各自干什么用的?
1)<uses-permission>is a tag which used to declare permission to access a restricted
resource/component of another application;
2)<use-feature> element is used to state all the features of a device that used by your
application.
5.adb是什么?有什么用?
adb is a command .It used to interact with Android emulator directly from the command line or from the script.
六、其他:
1.周期性Alarm用什么方法创建?
Create a repeating alarm need to use the setRepeating() method of the
AlarmManager class.
2.安卓支持哪几种Location Provider?如何获得位置提供者,具体方法类有哪些?
GPS、Cell tower triangulation 、Public wi-fi hotspots
Android uses the LocationManager class and the getProvider() method to find the name of all the location providers that are available on the mobile device.
3.安卓收到一个短信,会触发什么样的broadcast?
When an SMS is received by an Android system,it triggers a broadcast with action as SMS_RECEIVED,which notifies all the receivers that an SMS has been received.
4.什么是ADT-Plugin?
ADT-Plugin is a plug-in for eclipse that allows you to create and debug the android application quickly and easily
七、情景编程:(给出清晰的概念、思路、过程既可,不要求精确代码)
1.发送短信,拨叫某个号码(可以是直接拨叫、也可以是启动拨号面板,不考虑权限问题)
Answer:
1.Send and receive an SMS
1、发送SMS,代码要做3件事情:
1)获取SmsManager:SmsManager smsM = SmsManager.getDefault(); // static 2)申请权限:<uses-permission android:name="android.permission.SEND_SMS"/> 3)发送:smsM.sendTextMessage(String dstAddr, // 对方手机号, e.g. "139139139139"
String smsc, // SMSC(Short Message Service Center)地址,null取默认
String txt, // 内容
PendingIntent sent, // 发出后广播的消息(可能为OK, 可能为Fail)
PendingIntent deliver); // 对方收到后广播的消息
要接收sent 消息:
PendingIntent in = getBroadcast(Context c,
int reqtCode, // 未用
Intent i, // sent 本身
int flags) //
>>>> demo
2.拨号:
1、Making Telephonic Calls
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:5623451") );
ACTION_CALL // 直接拨号, 须权限
ACTION_DIAL // 仅打开拨号面板, 无须权限
startActivity(intent);
2.如何从内部、外部(SD卡)存储器存取文件
Answer:
1)Internal Data Storage:
To create a file on the internal storage for writing data:
1.Open or create the file by using the openFileOutput() method of the
android.content.Context class;
2.Write data to the file by using the write() method of java.io.FileOutputStream class;
3.Close the file by using the close() method of java.io.FileOutputStream class.
String FILENAME=”Mydata.txt”;
String mydata=”My name is Sam”;
FileOutputStream fos = openFileOutput(FILENAME,Context.MODE_PRIV ATE);
Fos.write(myData.getBytes());
Fos.close();
To open file from the internal storage for reading data:
1.Open or create the file by using the openFileIntput() method of the
android.content.Context class;
2.Write data to the file by using the read() method of java.io.FileIntputStream class;
3.Close the file by using the close() method of java.io.FileIntputStream class.
String FILENAME=”Mydata.txt”;
FileInputStream fis = openFileInput(FILENAME);
byte[] reader = new byte[fis.available()];
if (fis.read(reader)!= -1)
String myData = new String(reader);
Fis.close();
2)External Data Storage:
申请权限
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”>
String MYFILE = “MyData.txt”;
String myData = “My name is Sam”
FileOutputStream fos = new FileOutputStream(Environment.getExternalStorageDirectory()+ “//”+MYFILE):
byte[] reader = new byte[fis.available()];
fos.write(myData.getBytes());
Fos.close();
FileInputStream fis - new FileInputStream(Environment.getExternalStorageDirectory()+
“//”+MYFILE);
Byte [] reader = new byte[fis.avilablea()];
While(fis.read(reader)!= -1) {}
String mData = (new String(reader));
Fis.close();
3.如何获取当前地理位置.
a.申请权限
<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION”>
</uses-permission>
b.获取LocationManger
LocationManger lm=(LocationManger)getSystemService(Context.LOATION_SERVICE);
c.选择一个provider
d.获取location
Location location = lm.getCurrentLocation(provider);
4.如何显示一个Status Bar Notification.
Step1:获取NotificationManager实例
String serviceName = Context.NOTIFICATION_SERVICE;
NotificationManager nm = (NotificationManager)getSystemService(serviceName);
Step2:创建Notification 对象:
//The message to be shown on the status bar
String msg = "Notification msg";
long when= System.currentTimeMillis();
int icon = R.drawable.icon;
Notification notification = new Notification(icon, msg, when);
Step3:设置拉出notification window 后显示的内容
setLatestEventInfo(Context con, CharSequence title, CharSequence text, PendingIntent i);
5.如何播放res/raw/abc.mp3.
MediaPlayer mediaplayer = MediaPlayer.create(context,R.raw.abc.mp3);
Mediaplayer.start();
6.如何打开一个contact with ID 3.
Answer:
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI,
null,”DISPLAY_NAME = …”+ name”…“,null,null);
if(cusor.moveToFirst()){
String contactID = 3;
String contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISP
LAY_NAME));
}
7.如何找到一个ID为tabHost的View
Answer:
View mView = (View)findViewById(R.id.tabHost);
8.如何点按一个Button后,让某个TextView内容发生变化。
private Button btn;
private TextView tv;
btn = (Button)findViewById(R.id.button1);
tv = (TextView)findViewById(R.id.textView1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
tv.setText("fuck you");
}
});。