Android期末復(fù)習(xí)題總結(jié)2_第1頁
Android期末復(fù)習(xí)題總結(jié)2_第2頁
Android期末復(fù)習(xí)題總結(jié)2_第3頁
Android期末復(fù)習(xí)題總結(jié)2_第4頁
Android期末復(fù)習(xí)題總結(jié)2_第5頁
已閱讀5頁,還剩38頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

Intent的Component屬性的作用是什么,如何定義此屬性?

component(組件),指定Intent的的目標(biāo)組件的類名稱。通常Android會(huì)根據(jù)Intent中包含的其它屬性

的信息,比如action、data/type.category進(jìn)行查找,最終找到一個(gè)及之匹配的目標(biāo)組件。但是,如果

component這個(gè)屬性有指定的話,將直接使用它指定的組件,而不再執(zhí)行上述查找過程。指定了這個(gè)屬性以

后,Intent的其它所有屬性都是可選的。

Component屬性的作用是用來指定Intent的目標(biāo)組件的類名稱。如果Component這個(gè)屬性被指定了的話,

Intent的其它屬性都是可選項(xiàng),Android會(huì)直接使用Component指定目標(biāo)組件,而不再執(zhí)行其它查找過程。

在使用時(shí),需要先創(chuàng)建一個(gè)ComponentName對(duì)象,然后將它設(shè)置成Intent對(duì)象的Component的屬性。通過

setCoirponent()>selClassO和sHClassNameO三種方法都可以設(shè)置組件的名稱,通過getComponent()方

法則可獲得設(shè)置項(xiàng)。

2.發(fā)送廣播時(shí),可以通過sendCatagoryBroadcastO方法將Intent對(duì)象發(fā)送出去().(錯(cuò))

3、Android是什么?一種操作系統(tǒng)

4.下面關(guān)于Androiddvm的進(jìn)程和Linux的進(jìn)程,應(yīng)用程序的進(jìn)程說法正確的是()

DVM指dalivk的虛擬機(jī)。每一個(gè)Android應(yīng)用程序都在它自己的進(jìn)程中運(yùn)行,都擁有一個(gè)獨(dú)立的Dalvik

虛擬機(jī)實(shí)例。而每一個(gè)DVM都是在Linux中的一個(gè)進(jìn)程,所以說可以認(rèn)為是同一個(gè)概念。

5、Android操作系統(tǒng)最早由哪個(gè)公司研發(fā)?()Android公司

6.下列中不屬于手持設(shè)備的是()機(jī)頂盒

7、下列不是手機(jī)操作系統(tǒng)的是()oWindowsVista

8、到目前為止,Android操作系統(tǒng)的最高版本是哪個(gè)?()AndroidL

9、安裝AndroidSDK時(shí),可以通過()在線安裝或離線安裝。Androidsdkmanager

10、開發(fā)Android應(yīng)用程序時(shí),一般使用的計(jì)算機(jī)語言是()。JAVA

11,E/AndroidRuntime(1099):java.lang.RuntimeException:Unabletoinstantiateactivity

Componentlnfo{com.test/com.test.CanvasActivitys}:java.lang.ClassNotFoundException:

com.test.CanvasActivitysinloaderdalvik.system.PathClassLoadcr[/data/app/com.tcst-1.apk]這

段話是程序報(bào)錯(cuò)在LogCat中產(chǎn)生的記錄,從中可以分析問題的原因可能在哪里?()

Canva類沒有在AndroidManifest中正確申明sActivitys

12.對(duì)于直接Intent,Android不需要去做解析,因?yàn)槟繕?biāo)組件已經(jīng)很明確,Android需要解析的是那些間

接Intent,通過解析,將Intent映射給可以處理此Intent的ActivityJntentReceiver或Service(對(duì))

Intent可以傳遞View對(duì)象(錯(cuò))

Intent起著一個(gè)媒體中介的作用,專門提供組件互相調(diào)用的相關(guān)信息,實(shí)現(xiàn)調(diào)用者及被調(diào)用者之間的解耦

(對(duì))

通過Intent可以刪除程序(對(duì))

13.下面退出Activity錯(cuò)誤的方法是()。System,exit()

14.當(dāng)啟動(dòng)一個(gè)Activity并且新的Activity執(zhí)行完后需要返回到啟動(dòng)它的Activity來執(zhí)行的回調(diào)函數(shù)是

()ostartActivityResultO

15、這是一個(gè)資源配置文件,下面描述正確的是?()這個(gè)shape文件是畫一條虛線,實(shí)線段5dp,間隔3dp

16.Toasttoast=newToast(this);toast.setText(〃今天天氣不錯(cuò)\n哈哈〃);toast.show();上面代碼

的執(zhí)行結(jié)果是什么()。

代碼會(huì)拋出異常,因?yàn)閚ew出的Toast對(duì)象不能再使用setText方法來設(shè)置提示框文本

17、setOnTouchEvent設(shè)置返回值為true和false有何區(qū)別?()

返回true表示這個(gè)消息已經(jīng)被處理結(jié)束,后續(xù)的handler不再接收到這個(gè)消息

18、下列哪個(gè)可做EditText編輯框的提示信息()。android:hint

19、使進(jìn)度條變橫向的系統(tǒng)樣式是()0android:style/Widget.ProgressBar.Horizontal

20、關(guān)于Android事件機(jī)制及事件監(jiān)聽,下列說法不正確的有1)。

i.View類里的eventlistener是一個(gè)帶有回調(diào)方法的接口,當(dāng)UI里的組建是被用戶觸發(fā)時(shí),這些方法會(huì)

被系統(tǒng)框架所調(diào)用;(對(duì))

ii.來自View.OnClickListener,當(dāng)點(diǎn)擊這個(gè)Item(在觸摸模式),或者當(dāng)光標(biāo)聚集在這個(gè)Item上時(shí)按下

“確認(rèn)”鍵,導(dǎo)航鍵,或者軌跡球,它會(huì)被調(diào)用;(對(duì))

iii,來自View.OnLongClickListener,當(dāng)長按這個(gè)Item(在觸摸模式),或者當(dāng)光標(biāo)聚集在這個(gè)Item上時(shí)

長按“確認(rèn)”鍵,導(dǎo)航鍵,或者軌跡球,它會(huì)被調(diào)用;(對(duì))

iv.來自View.OnFocusChangeListener,當(dāng)手移到或離開這個(gè)Item,它會(huì)被調(diào)用(對(duì))

v.來自View.OnKeyListener,當(dāng)光標(biāo)移到這個(gè)Item,按下和釋放一個(gè)按鍵的時(shí)候,它會(huì)被調(diào)用;(對(duì))

vi.來自View.OnTouchListener,在這個(gè)Item的范圍內(nèi)觸摸的時(shí)候,它會(huì)被調(diào)用;(對(duì))

vii.來自View.OnCreateContextMenuListener,當(dāng)上下文菜單被建立時(shí),只需短按一下,它會(huì)被調(diào)用。

(錯(cuò))

21.關(guān)于對(duì)話框,下面說法正確的是()。對(duì)話框的父類不是View

22.創(chuàng)建一個(gè)提示對(duì)話框,應(yīng)創(chuàng)建下面哪種對(duì)話框?qū)嵗ǎ?。AlertDialog

23、在AlertDialog中,以下哪個(gè)方法是用于取消的()。setNegativeButton

24.在android中使用Menu時(shí)可能需要重寫的方法有()。(1)onCreateOptionsMenu()(3)

onOptionsItemSelectedO

25.鍵盤事件處理方法中,以下哪個(gè)方法是用來處理鍵盤按鍵的釋放事件的()。keyReleased(int

keyCode)

26.下面Android的存儲(chǔ)方式中,除SharedPreferences外還有哪種方式是不可以將數(shù)據(jù)在不同應(yīng)用間數(shù)據(jù)

共享的()oFiles

27、當(dāng)使用文件存儲(chǔ)的時(shí)候,默認(rèn)創(chuàng)建的文件會(huì)放在什么位置()。app

28、關(guān)于SharedPreferences和文件存儲(chǔ)數(shù)據(jù)描述正確的是()。使用文件存儲(chǔ)需要?jiǎng)?chuàng)建文件,而

SharedPreferences的存儲(chǔ)方式自動(dòng)創(chuàng)建xml文件

29、使用SharedPreferences進(jìn)行數(shù)據(jù)存儲(chǔ)的時(shí)候,下面哪個(gè)方法是不參及的()ceditO

30、使用SharedPreferences存儲(chǔ)數(shù)據(jù)時(shí),會(huì)創(chuàng)建一個(gè)什么類型的文件來進(jìn)行數(shù)據(jù)存放()。.xml文

40、在RelativeLayout布局中,有一個(gè)id為entry的EditText,目前有一個(gè)Button想放置在其左邊,應(yīng)

為Button指定什么屬性設(shè)置()oandroid:layout_toLeftOf=〃@id/entry〃

41.在一個(gè)相對(duì)布局中怎樣使一個(gè)控件居中()。android:layout_centerInParent二〃true”

42.在表格布局中,android:collapseColumns二T,2〃的含義是:()在屏幕中,不管是否能都顯示完,折

疊1.2列

43.絕對(duì)布局中,android:layoujx的含義有()以手機(jī)左,為原點(diǎn),組件顯示到屏幕中的橫向坐標(biāo)值。

44、簡(jiǎn)述開發(fā)手機(jī)聯(lián)盟?

開放手機(jī)聯(lián)盟(OHA,OpenHandsetAlliance,)是美國Google公司及2019年11月5日宣布組建的一個(gè)

全球性的聯(lián)盟組織,網(wǎng)址為http://openhandsetal1iance。這一聯(lián)盟將會(huì)支持Google可能發(fā)布的手機(jī)操

作系統(tǒng)或者應(yīng)用軟件,共同開發(fā)名為Android的開放源代碼的移動(dòng)系統(tǒng)。開放手機(jī)聯(lián)盟包括手機(jī)制造商、手

機(jī)芯片廠商和移動(dòng)運(yùn)營商等幾大類,目前聯(lián)盟成員數(shù)量已經(jīng)達(dá)到了80家。

45.以下哪一個(gè)類可以實(shí)現(xiàn)廣播接收的功能()oBroadcastReceiver

46.Android系統(tǒng)有哪些特點(diǎn)?

(1)應(yīng)用框架可以重復(fù)使用,其組件也可以更換;(2)Dalvik虛擬機(jī)針對(duì)移動(dòng)設(shè)備進(jìn)行了優(yōu)化;(3)優(yōu)

化的圖形能力支持2D/3D圖形(OpenGLESLO);(4)集成了基于開源WebKit引掣的瀏覽器;(5)采用

SQLite實(shí)現(xiàn)結(jié)構(gòu)化數(shù)據(jù)存儲(chǔ);(6)多媒體支持多種音頻、視頻格式;(7)GSMTelephony(hardwaredependent);

(8)支持藍(lán)牙Bluetooth,3G和WiFi;(9)支持照相機(jī)、GPS、指南針和加速度儀等傳感器硬件;(10)

豐富的開發(fā)環(huán)境,包括模擬機(jī)、調(diào)試工具、內(nèi)存運(yùn)行檢測(cè),以及為EclipseIDE所寫的插件。

47、在AndroidManifest.xml中注冊(cè)一個(gè)廣播,需要使用什么標(biāo)簽()?〈receiver〉

48、定義廣播需要重寫父類中的什么方法()。onCreate

49、在程序中,發(fā)送廣播的方法是以下哪一個(gè)()osendBroadcast

50定義一個(gè)廣播,需要繼承哪個(gè)類(BroadcastReceiver)

51.簡(jiǎn)述Android應(yīng)用程序的組成。

52、一般來說,Android程序包含如下主要的組件類:活動(dòng)(Activity);用于表現(xiàn)功能服務(wù)(Service);相

當(dāng)于后臺(tái)運(yùn)行的Activity廣播接收器(BroadcastReceiver)用于接收廣播意圖;Intent用于連接

以上各個(gè)組件,并在其間傳遞消息;ContentProviders實(shí)現(xiàn)不同組件之間的數(shù)據(jù)共享;View提供了可視化

界面的展示。

53、Dalvik虛擬機(jī)及Sun公司定義的標(biāo)準(zhǔn)虛擬機(jī)(JVM)有何不同?

54、Dalvik和JVM的首要差別是Dalvik基于寄存器而JVM基于棧,基于寄存器的虛擬機(jī)對(duì)于更大的程序來

說,在它們編譯的時(shí)候,花費(fèi)的時(shí)間更短;(2)Dalvik主要是完成對(duì)象生命周期管理,堆棧管理,線程管

理,安全和異常管理,以及垃圾回收等等重要功能;(3)Dalvik負(fù)責(zé)進(jìn)程隔離和線程管理,每一個(gè)Android

應(yīng)用在底層都會(huì)對(duì)應(yīng)一個(gè)獨(dú)立的Dalvik虛擬機(jī)實(shí)例,其代碼在虛擬機(jī)的解釋下得以執(zhí)行;(4)不同于JVM

運(yùn)行Java字節(jié)碼,Dalvik虛擬機(jī)運(yùn)行的是其專有的文件格式dex,dex文件格式可以減少文件整體尺寸,提

高I/O操作的類查找速度;(5)所有的Android應(yīng)用的線程都對(duì)應(yīng)一個(gè)Linux線程,虛擬機(jī)因而可以更多

的依賴操作系統(tǒng)的線程調(diào)度和管理機(jī)制。

55、請(qǐng)談一下Android系統(tǒng)的架構(gòu)

Android系統(tǒng)采用了分層架構(gòu),從高層到低層分別是應(yīng)用程序?qū)?、?yīng)用程序框架層、系統(tǒng)運(yùn)行庫層和linux

核心層。

54、Android開發(fā)環(huán)境搭建需要哪些主要步驟?

安裝Java安裝Eclipse安裝AndroidSDK安裝Eclipse插件ADT

55.Windows環(huán)境下如何檢測(cè)已經(jīng)安裝成功Java?

寫一個(gè)簡(jiǎn)單的java程序來測(cè)試JDK是否已安裝成功:

publicclassHelloWorldf

publicstaticvoidmain(String[]args){

System.out.printIn("Helloworld!”);

將以上代碼保存為文檔名為HelloWorld.java的文檔。打開命令提示符窗口,進(jìn)入到

HelloWorld.java所在目錄,鍵入下面的命令:

javacHelloWorld.java

javaHelloWorld

如果屏幕如圖,能夠正確輸出且不泥示錯(cuò)誤,表示JDK開發(fā)環(huán)境配置完成。

56.什么是AVD,有哪些特點(diǎn)?

AndroidVirtualDevice是一個(gè)經(jīng)過配置的模擬器,可以模擬顯示屏幕的大小、屏幕分辨率、觸摸屏、軌

跡球、鍵盤、GPS、聲音播放、SD卡支持,緩存區(qū)大小等。AVD也存在著缺點(diǎn),不能模擬重力感應(yīng)、麥克風(fēng)

等一些硬件設(shè)備,因此有時(shí)候也需要實(shí)體手機(jī)上運(yùn)行和測(cè)試Android應(yīng)用程序。

57、什么是ADT?

AndroidDevelopmentToolsplugin(ADT)是使用Eclipse進(jìn)行Android移動(dòng)應(yīng)用開發(fā)的一個(gè)方便的開發(fā)、

仿真測(cè)試平臺(tái)。

59、58、在手機(jī)的實(shí)機(jī)上進(jìn)行開發(fā)調(diào)試需要在手機(jī)上如何設(shè)置?

60、在手機(jī)上進(jìn)行開發(fā)調(diào)試需要在手機(jī)上進(jìn)行設(shè)置,選擇設(shè)置一應(yīng)用程序-開發(fā)-USB調(diào)試,之后USB連接開

發(fā)計(jì)算機(jī)才能進(jìn)行開發(fā)調(diào)試。

Activity,intent、Service和BroadCastReceiver之間是什么關(guān)系

60、Intent的Action、Category屬性的作用是什么?

Action屬性主要用來定義Intent要執(zhí)行的抽象動(dòng)作,它是一個(gè)字符串。使用時(shí)只需在程序中定義,并在要

訪問組件的〈intent-filter…/〉子元素中聲明就可以使用了「Category屬性是對(duì)Action定義動(dòng)作的補(bǔ)充,

也是一個(gè)普通的字符串,通常兩者結(jié)合使用。

在文件AndroidManifest.xml里,〈Activity…/〉元素中所配置的子元素〈intent-filter…/〉的作用就是

用于指定該Activity可響應(yīng)的Intent。

61.Intent的Data、Type屬性的作用是什么?

Intent的Data屬性的作用是向Action屬性提供操作的數(shù)據(jù)。Data屬性接受一個(gè)Uri對(duì)象,此對(duì)象可以決

定所要操作數(shù)據(jù)的類型及數(shù)據(jù)的具為值。

可以通過設(shè)置Type屬性來顯式指定特定類型數(shù)據(jù)(MIME)。一般Intent會(huì)根據(jù)數(shù)據(jù)本身對(duì)其數(shù)據(jù)類型進(jìn)行判

定,但是如果使用Intent的Type屬性進(jìn)行設(shè)置,可以實(shí)現(xiàn)強(qiáng)制顯式指定的類型而不再進(jìn)行推導(dǎo)。

62.簡(jiǎn)述Intent的功能及作用。

Intent是Android中各種組件之間傳送信息的“信使”。中文里Intent有“意圖、目的”的意思,在這

里仍兼有這樣的含義,因?yàn)樵诮M件之間導(dǎo)航的過程中,我們也需要使用Intent將意圖一并傳遞過去。上一

章中,在一個(gè)Activity里激發(fā)另一個(gè)Activity的例子中就體現(xiàn)了Intent的功能。

使用Intent的好處就是應(yīng)用程序可以啟動(dòng)只具有某種特征的的組件,而不必指定某個(gè)具體的組件。Intent

中可以封裝不同組件之間進(jìn)行導(dǎo)航的意圖。這些意圖需要通過Intent的屬性來表現(xiàn)。

63.Intent的實(shí)現(xiàn)策略分為幾種類亂請(qǐng)分別敘述。

Inlent的實(shí)現(xiàn)策略即指Intent尋找組件的方法。這種策略分為兩種:一種是直接Intent,也稱為顯式

Intento另一種是間接Intent,也稱為隱式Intent。

直接Intent方式需要通過指定Intent的Component屬性(調(diào)用setComponent(ComponentName)或者

setClass(Context,Class)來指定)來實(shí)現(xiàn).這樣應(yīng)用就會(huì)對(duì)應(yīng)的啟動(dòng)所指定的具體組件類。在以上對(duì)

Intent的Component屬性的介紹中就說明過。這種策略主要在源組件知道目標(biāo)組件名稱的情況下使用。

間接Intent策略中沒有指定Component屬性的Intent,尋找組件需要通過〈intent-filter…/〉子元素

來實(shí)現(xiàn)。這就要求Intent中包含足夠的信息,這樣系統(tǒng)才能根據(jù)這些信息,在所有的可用組件中,確定

出滿足Intent的組件c

64、Android系統(tǒng)提供的Acticn常量有哪些,如何使用。

Action常量常量值(字符串)動(dòng)作說明

ACTION_CALLandroid,intent,action.CALL呼叫指定用戶

ACTION_EDITandroid,intent,action.EDIT對(duì)于指定數(shù)據(jù)進(jìn)行編輯

ACTIONVIEWandroid,intent,action.VIEW向用戶顯示指定數(shù)據(jù)

ACTION_PICKandroid,intent,action.PICK從列表中選擇并返回某項(xiàng)目

ACTIOOIALandroid,intent,action.DIAL顯示打電話面板,可以實(shí)現(xiàn)緊急呼叫

ACTIONSENDandroid,intent,action.SEND向他人發(fā)送數(shù)據(jù)(短信)

ACTION_ANSWERandroid,intent,action.ANSWER應(yīng)答電話

65.如何在程序清單文件AndroidManifest.xml中配置Activity?

對(duì)于應(yīng)用程序中的每一個(gè)Activity我們都需要在程序清單文件AndroidManifest.xml中進(jìn)行配置,這

樣才能有機(jī)會(huì)運(yùn)行。這種配置也是非常簡(jiǎn)單的,方法就是在程序清文件的〈application…元素中添加

〈Activity…/〉子元素即可。添加時(shí)一般要注明該Activity的以下三個(gè)屬性:

(1)name:指明要配置的Activity的實(shí)現(xiàn)類

(2)icon:指明要配置的Activity的圖標(biāo)

(3)label:指明要配置的Activity的標(biāo)簽

在文件AndroidManifest.xml中我們除了要配置每一個(gè)Activity外,還需進(jìn)行子元素

〈intent-filter…/〉的配置,該元素用于指定Activity可響應(yīng)的Intent。對(duì)于每一個(gè)應(yīng)用程序來說,無論

它是由幾個(gè)Activity組成,但只有一個(gè)Activity是它的入口。到底哪一個(gè)是人口的Activity,這得由清

單文件中的子元素〈intent-filter”〉來決定。如果想指定某個(gè)Activity為程序入口,這時(shí)需在其對(duì)應(yīng)的

子元素〈片快睢-衍11°廣??/〉中必須具備如下屬性:

(actionandroid:name="andmid.intent,action.MAIN"'/>

(categoryandroid^ame^android.intent,category.LAUNCHER"/>

66.介紹及Activity生命周期相關(guān)的回調(diào)方法的功能及使用方法。

及Activity生命周期相關(guān)的回調(diào)方法主要有以下七個(gè):

(1)onCreateO:當(dāng)創(chuàng)建一個(gè)Activity時(shí),系統(tǒng)會(huì)回調(diào)onCreate。方法進(jìn)行初始化設(shè)置,如創(chuàng)建視圖、綁

定數(shù)據(jù)至列表。

(2)onStart():當(dāng)一個(gè)Activity開始執(zhí)行時(shí)此方法被回調(diào),這時(shí)的Activity是可見的,會(huì)緊跟在

onCreate()方法后面執(zhí)行。

(3)onResumeO:當(dāng)一個(gè)Activity真正開始運(yùn)行或重新恢復(fù)時(shí)被回調(diào),此時(shí)會(huì)獲得焦點(diǎn)。

當(dāng)一個(gè)Activity運(yùn)行時(shí),如果用戶又激活了另一個(gè)Activity,這時(shí)第一個(gè)Activity將會(huì)被暫停。在第一

個(gè)Activity在沒有被殺死的情況下,以后又有了重新運(yùn)行的機(jī)會(huì),那么就會(huì)直接調(diào)用onResumeO方法將其

恢復(fù)。

(4)onPauseO:暫停Activity時(shí)被回調(diào)。

如果在一個(gè)Activity運(yùn)行時(shí),用戶又激活了另一個(gè)Activity,這時(shí)將會(huì)調(diào)用第一個(gè)Activity的onPauseO

方法將其暫停。在Activity的狀態(tài)變換過程中onResumeO和onPauseO方法經(jīng)常被調(diào)用,因此在使用中應(yīng)

使用簡(jiǎn)單高效的代碼。

(5)onStopO:停止Activity時(shí)被回調(diào)。

如果在一個(gè)Activity運(yùn)行吐用戶又激活了另一個(gè)Activity,而且第一個(gè)Activity很久都沒有得到再次

運(yùn)行機(jī)會(huì),就會(huì)調(diào)用onStopO方法將第一個(gè)Activity停止。

(6)onReStart():在Activity從停止?fàn)顟B(tài)轉(zhuǎn)換到活動(dòng)狀態(tài)前,回調(diào)該方法。

當(dāng)一個(gè)處于停止?fàn)顟B(tài)的Activity又獲得了用戶輸入焦點(diǎn),就會(huì)調(diào)用?!窻estart()方法,重新開始執(zhí)行這個(gè)

Activity。

(7)onDestroyO:在銷毀Activity前,即進(jìn)入非活動(dòng)狀態(tài)前,回調(diào)該方法。

67.Activity在其生命周期中會(huì)處于哪幾種狀態(tài)?

一個(gè)Activity在其生命周期中會(huì)在四個(gè)重要狀態(tài)間進(jìn)行轉(zhuǎn)換.下面分別說明各狀態(tài):

(1)活動(dòng)狀態(tài),處于該狀態(tài)時(shí),Activity位于前臺(tái),用戶可見且可獲得焦點(diǎn);

(2)暫停狀態(tài),處于該狀態(tài)時(shí),該Activity仍可見,但失去焦點(diǎn),其它Activity位于前臺(tái);

(3)停止?fàn)顟B(tài),處于該狀態(tài)時(shí),Activity不可見且失去焦點(diǎn);

(4)銷毀狀態(tài),處于該狀態(tài)時(shí),Activity被系統(tǒng)或進(jìn)程結(jié)束。

68、如何將一個(gè)Activity設(shè)置成窗口的樣式。

在AndroidManifest.xml中定義Activity的地方添加:

android:theme二"?android:style/Theme.Dialog^或

android:theme=,^?android:style/Theme.Translucentv就變成半透明的

69、使用資源包括哪幾種方法?

(1)在代碼里使用資源類;(2)在代碼里調(diào)用資源類并實(shí)例化;⑶從其他資源類里引用。

70、談?wù)刟ndroid中常用的幾種布局。

在Android中,共有五種布局方式,分別是:FramcLayout(框架布局),LinearLayout(線性布局),

AbsoluteLayout(絕對(duì)布局),RelaiiveLayout(相對(duì)布局),TableLayout(表格布局)。

(DFrameLayout框架布局,放入其中的所有元素都被放置在最左上的區(qū)域,而且無法為這些元素指定一個(gè)

確切的位置,下一個(gè)子元素會(huì)重疊覆蓋上一個(gè)子元素,適合瀏覽單張圖片。

(2)LinearLayout線性布局,是應(yīng)用程序中最常用的布局方式,主要提供控件水平或者垂直排列的模型,

每個(gè)子組件都是以垂直或水平的方式來定位(默認(rèn)是垂直)。

(3)AbsoluteLayout絕對(duì)定位布局,采用坐標(biāo)軸的方式定位組件,左上角是(0,0)點(diǎn),往右x軸遞增,往下

Y軸遞增,組件定位屬性為android:layout_x和android:layout_y來確定坐標(biāo)。

(4)RelativeLayout相對(duì)布局,根據(jù)另外一個(gè)組件或是頂層父組件來確定下一個(gè)組件的位置。和CSS里面的

類似。

(5)TableLayout表格布局,類似Html里的Table,使用TableRow來布局,其中TableRow代表一行,

TahleRow的每一個(gè)視圖組件代表一個(gè)單元格c

7kandroid中常用的數(shù)據(jù)存儲(chǔ)方式有哪些?

常用的數(shù)據(jù)存儲(chǔ)方式:SharePreference存儲(chǔ)、File存儲(chǔ)(分為手機(jī)內(nèi)存存儲(chǔ)和SD卡存儲(chǔ))、SQLite數(shù)據(jù)

庫存儲(chǔ)和網(wǎng)絡(luò)存儲(chǔ)。

72.一個(gè)Activity就是一個(gè)可視化的界面或者看成是控件的容器。(對(duì))

73、Intent有很長的生命周期,是沒有用戶界面的程序,可以保持應(yīng)用在后臺(tái)運(yùn)行,而不會(huì)因?yàn)榍袚Q頁面

而消失。(錯(cuò))

74.當(dāng)Antivity的啟動(dòng)模式設(shè)置為SingleTop表示當(dāng)該Anctivity的實(shí)例在棧頂時(shí)只會(huì)產(chǎn)生一個(gè)實(shí)例。(對(duì))

75.onPauseO方法在activity被暫?;蚴栈豤pu和其他資源忖調(diào)用,該方法用于保存活動(dòng)狀態(tài)的,也是對(duì)

運(yùn)行時(shí)數(shù)據(jù)的現(xiàn)場(chǎng)保護(hù)。(對(duì))

76、onDestroy是activity被結(jié)束掉前最后一個(gè)被調(diào)用方法,當(dāng)調(diào)用finish方法或者系統(tǒng)為了節(jié)省空間將

它暫時(shí)性的結(jié)束掉時(shí)候調(diào)用。(對(duì))

77、不是所有的Activity都有自己的生命周期。(錯(cuò))

78、onPause()是service的生命周期方法(錯(cuò))

79、如果sendee已經(jīng)啟動(dòng),再次啟動(dòng)該服務(wù)時(shí)將先后調(diào)用onCreateO和onStartCommandO方法。(錯(cuò))

80^利用HttpURLConnection的.getlnputStreamO方法得到的是字符流。(錯(cuò))

81.程序中使用htlp協(xié)議從網(wǎng)上下載文件時(shí),無需設(shè)置訪問網(wǎng)絡(luò)的權(quán)限。(錯(cuò))

82.使用startService()方法啟動(dòng)服務(wù)后,調(diào)用者和服務(wù)間沒有關(guān)聯(lián),即使調(diào)用者退出了,服務(wù)任然進(jìn)行。

(對(duì))

83.當(dāng)應(yīng)用程序中某廣播在AndroidMainifest進(jìn)行注冊(cè)后,即使該應(yīng)用程序關(guān)閉后,也可以接受操作系統(tǒng)

發(fā)出的廣播信息。(對(duì))

84、Ulthread通常就是mainthread,Android啟動(dòng)程序時(shí)會(huì)替它建立一個(gè)MessageQueue。(對(duì))

85.廣播接收器可以在Activity中單獨(dú)注冊(cè)及注銷。(對(duì))

86.廣播接收器只能在配置文件中注冊(cè)「(錯(cuò))

87、對(duì)下面代碼:notification.vibrate=newlong[]{100,200,100,500),其中notification是通知管理

器對(duì)象表示我們對(duì)Notification沒置了震動(dòng),并且是100ms延遲后,震動(dòng)200nls,然后停止100ms,再震動(dòng)

500ms(對(duì))

88、使用Notification時(shí),需要發(fā)送廣播實(shí)現(xiàn)notify。(錯(cuò))

89在AndroidManifest.xml中注冊(cè)廣播,需要使用標(biāo)簽。(對(duì))

90^有2種方式注冊(cè)BroadcastReceiver的方法,一是靜態(tài)的在AndroidManifest.xml巾注冊(cè),二是動(dòng)態(tài)的在

代碼中注冊(cè)。()(對(duì))

91.如果需要一個(gè)通知立即顯示,那么在構(gòu)造Notification對(duì)象的時(shí)候,需耍在構(gòu)造函數(shù)的第三個(gè)參數(shù)中傳

遞newCalendar。的值(錯(cuò))

92.取消注冊(cè)BroadcastReceiver,調(diào)用Context.unregisterReceiver()方法(對(duì))

93.編寫用Intent實(shí)現(xiàn)的用戶登錄程序。

要求:在第一個(gè)界面上輸入用戶名和密碼,在第二個(gè)界面上顯示前一界面中輸入的用戶名和密碼。

MainActivity.java:

packagecom.example.androidintent;

importandroid.os.Bundle;

importandroid.app.Activity;

importandroid,content.Context:

importandroid,content.Intent;

importandroid,view.View;

importandroid,view.View.OnClickListener;

importandroid.widget.Button;

importandroid,widget.EditText:

importandroid.widget.Text.Vip\v:

publicclassMainActivityextendsActivity{

privateTextViewuser,pass;

privateEditTextusername,password;

privateButtonloca;

?Override

protectedvoidonCreate(BundlesavedlnstanceState){

super.onCreate(savedlnstanceState);

setContentView(R.layout,activitymain);

user=(TextView)findViewById(R.id.user);

pass-(TextView)findViewById(R.id.pass);

username=(EditText)findViewByld(R.id.username);

password=(EditText)findViewBy!d(R.id.password);

loca=(Button)findViewById(R.id.loca);

loca.setOnClickListener(newMyButtonListener());

classMyButtonListenerimplementsOnClickListener{

?Override

publicvoidonClick(Viewv){

Stringtxl=usernane.getTextQ.toStringO;

Stringtx2=password.getTextO.toStringO;

Intentintent=newIntent();

intent.putExtraCtxl*,txl);

intent.putExtra(,,tx2",tx2);

intent.spt.Class(MainActivity.this,OthftrActivity,class);

MainActivity.this.startActivity(intent);

OtherActivity.java:

packagecom.example,androidintent;

importandroid.app.Activity;

importandroid.app.Activity;

importandroid,content.Intent;

importandroid.os.Bundle;

importandroid,view.View;

importandroid,widget.TextView:

publicclassOtherActivityextendsActivity(

privateTextViewtel,te2,te3,te4;

?Override

protectedvoidonCreate(BundlesavedlnstanceState){

super.onCreate(savedlnstanceState);

setContentView(R.layout.other);

Intentintent二getlntentO;

Stringvaluel二intent.getStringExtra("txl");

Stringvalue2=intent.getStringExtraC,tx2,/);

tel=(TextView)findViewById(R.id.tel);

te2=(TextView)findViewById(R.id.te2);

te3二(TextView)findViewById(R.id.te3);

te4=(TextView)findViewById(R.id.te4);

tp2.setText(valuel);

te4.setText(value2);

activity_main.xml:

<LinearLayoutxmlns:android=,/http://schemas.android/apk/res/android”

,/

xirlns:tools二〃http://schemas.android/tools

android:layout_width二〃match_parent〃

android:layout_height=,,match_parent/,

android:orientation="vertical”>

<TextView

android:id="@+id/user〃

androidilayoutjvidth-^wrapcontent7"

android:layout_height二,Tap_content〃

android:text="用戶名"/〉

<EditText

android:id="@+id/username〃

android:layout_width=*fill_parent,z

android:layout,height=xwrap_content,//>

<TextView

android:id="@+id/pass〃

android:layout_width=,,wrap_content〃

android:layout_height=、rap_content〃

android:text二〃密碼〃/〉

<EditText

android:id=〃@+id/password〃

android:layout_width二〃fill_parent〃

android:1ayout_height=*wrap_content*/>

(Button

android:id=*6+id/1oca”

android:1ayout_width=z,fi1l_parent"

android:layout_height=xwrap_content,"

android:text二〃登陸〃/>

</LinearLayout>

other.xml:

<?xmlversion-"1.0"encoding-〃utf-8〃?〉

<LinearLayoutxmlns:android=,,http://schemas,android/apk/res/android^

android:layout_width二〃match_parent”

android:layout_height=z,match_parentz,

android:orientation二〃horizontal”>

<TextView

android:id=〃@+id/1e1〃

android:layoutwidth二〃wrapcontent”

android:layoutheight=*wrapcontent,/

android:text二”用戶名:〃/>

<TextView

android:id=〃@+id/te2〃

android:layoutjvidth=,,vrapcontent”

android:]ayoutheight=*wrapcontent”

<TextViewandroid:id二〃@+id/te3”

android:layout_width二"wrapcontent”

android:!ayoutheight=,,wrap_content,/

android:text=〃密碼:〃/>

<TextView

android:id=〃@+id/te4〃

android:layoutjvidth^wrap-Content^

android:layoutheight="wrapcontent”

</LinearLayout>

string,xml:

<?xmlversion=〃1.0〃encoding="utf-8〃?〉

(resources)

(stringname="app_name"〉androidintent</string>

(stringname=,,action_settings,,>Settings</string>

<stringname=,,he11o_wor111oworld!</string>

</rescurces>

94.編寫程序?qū)崿F(xiàn)如下功能:

(1)程序包含2個(gè)Activity

(2)ActivityOl包含一個(gè)按鈕,點(diǎn)擊按鈕跳轉(zhuǎn)到Activity02;

(3)Activity02包含一個(gè)按鈕,點(diǎn)擊按鈕跳轉(zhuǎn)到ActivityOl。

ActivityOl.java:

packagecom.example.wpp_201942577two;

importandroid,app.Activity;

importandroid.content.Intent;

importandroid,os.Bundle;

importandroid,view.View;

importandroid,view.View.OnClickListencr;

importandroid.widget.Button;

publicclassActivityOlextendsActivity(

^Override

publicvoidonCreate(BundlesavedlnstanceState)

super.onCreate(savedlnstanceState);

setContentView(R.layout,activity);

Buttonbutton=(Button)findViewByld(R.id.buttonl);

button.setText(〃啟動(dòng)Ac:ivity02,/);

button.setOnClickListener(newOnClickListenerO:

?Override

publicvoidonClick(Viewv){

Intentintent二newIntent(ActivityOl.this,Activity02.class);

startActivity(intent);

Activity02.java

packagecom.example.wpp_201942577two;

importandroid.app.Activity;

importandroid.content.Intent;

importandroid.os.Bundle;

import.android,view.View;

importandroid.view.View.OnClickListener;

importandroid,widget.Button;

publicclassActivity02extendsActivity(

?Override

publicvoidonCreate(BundlesavedlnstanceState)

super.onCreate(savedlnstanceState);

setContentView(R.layout.activity02);

ButtonotherButton=(Button)findViewById(R.id.button3);

otherButton.setText(〃進(jìn)入ActivityOl");

otherButton.setOnClickListener(newOnClickListener(){

?Override

publicvoidonClick(Viewv){

Intentintent=newIntent(Activity02.this,ActivityOl.class);

startActivity(intent);

activityOl.xml:

<?xmlversion="1.0〃encoding="utf-8〃?〉

<LinearLayoutxmlns:android-^http://schemas,android/apk/res/android'"

android:layout_width="zmatch_parent

android:layoutJ^eight=",match_parent,,

android:orientalion=,,verticar,>

<TextViewandroid:id="@+id/textViewl〃

android:layoutwidth二〃口atch_parent〃

android:layoutheight^^wrapcontent”

android:text二〃ActivityOl”/>

(Buttonandroid:id二〃@+id/buttonl〃

android:layout_width=,,natch_parent,/

android:1ayout_height=xwrap_content

android:text二〃啟動(dòng)Activity”/>

</LinearLayout>

activity.02xml:

<?xmlversion=〃1.0〃encoding="utf-8〃?〉

<LinearLayoutxmlns:android^^http://schemas.android/apk/res/android,/

android:layout_width-〃match_parent”

android:layout_height=//match_parent,z

android:orientation二〃vertical”>

<TextView

android:id="/@+id/textViewl”

android:layout_width二〃口atch_parent〃

android:layoutheight="wrapcontent”

android:text二〃Activity02〃/>

<Button

android:id=〃@+id/button3”

android:layout_width=,,natch_parentz/

android:layout_height=*wrap_contentz,

android:text="Button”/>

</LinearLayout>

string,xml:

<?xmlversion二T.0〃encoding二〃utf-8”?〉

<resources>

(stringname=/,app_name/,>wpp_201942577Two</string>

(stringname=,,action_settings,,>Settings</string>

(stringname="hello_world,,>ActivityOK/string>

</rescurces>

95.使用CheckBox控件實(shí)現(xiàn)多項(xiàng)選擇。

要求:添加4個(gè)選項(xiàng),名稱分別為:swim、run、dance、walk

MainActivity.class:

packagecom.example,lab;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.view.Gravity;

importandroid,view.View;

importandroid.widget.Button;

importandroid.widget.CheckBox:

importandroid.widgetpoundButton;

importandroid,widget.TextView:

importandroid.widget.Toast;

publicclassMainActivityextendsActivity{

TextViewmTextViewl;

ButtonmBut.ton1;

CheckBoxmCheckBox1;

CheckBoxm_CheckBox2;

CheckBoxm_CheckBox3;

CheckBoxmCheckBox4;

/**Calledwhentheactivityisfirstcreated.*/

gOverride

publicvoidonCreate(BundlesavedlnstanceState){

super.onCreate(savedlnstanceState);

setContentView(R.layout,activitymain);

m_TextViewl-(TextView)findViewByld(R.id.textview);

m_Buttonl=(Button)findViewByld(R.id.buttc-nl);

mCheckBoxl=(CheckBox)findViewById(R.id.checkbox!);

m_CheckBox2=(CheckBox)findViewById(R.id.checkbox2);

m_CheckBox3=(CheckBox)findViewById(R.id.checkbox3);

m_CheckBox4=(CheckBox)findViewById(R.id.checkbox4);

mCheckBox1

.setOnCheckedChangeListener(newChecxBox.OnCheckedChangeListenerO(

publicvoidonCheckedChanged(CompoundButtonbuttonView,

booleanisChecked){

if(m_CheckBox1.isChecked()){

DisplayToast("你選擇了:〃+m_CheckBoxl.getTextO);

CheckBox2

.SAl.0nCheckf?dChangeI.ist.ener(newChpc<Rox.OnCheckedChangpList.pnnr(){

publicvoidonCheckedChanged(CompoundButtonbuttonView,

booleanisChecked){

if(m_CheckBox2.isChecked()){

DisplayToast("你選擇了:〃+m_CheckBox2.getTextO);

m_CheckBox3

.setOnCheckedChangeListener(newChecxBox.OnCheckedChangeListener(){

publicvoidonCheckedChanged(CompoundButtonbuttonView,

booleanisChecked){

if(mCheckBox3.isChecked()){

DisplayToast("你選擇了:"+m_CheckBox3.getTextO);

m_CheckBox4

.setOnCheckedChangeListener(newChecxBox.OnCheckedChangeListener(){

publicvoidonCheckedChanged(CompoundButtonbuttonView,

booleanisChecked){

if(m_CheckBox4.isChecked()){

DisplayToast("你選擇了:"+m_CheckBox4.getTextO);

mButtonl.setOnClickListener(newButton.OnClickListenerO{

publicvoidonClick(Viewv){

intnum=0;

if(m_CheckBoxl.isChecked()){

num++;

if(m_CheckBox2.isChecked0){

niim++;

if(mCheckBox3.isChecked()){

num++;

if(m_CheckBox4.isChecked()){

num++;

DisplayToast(〃謝謝參及!你一共選擇了〃+num+〃項(xiàng)!");

publicvoidDisplayToast(Stringstr){

Toasttoast=Toast.makeText(this,str,Toast.LENGTH_SHORT);

toast.setGravity(Gravity,0,240);

toast.show();

activityjnain.xml:

<?xmlversion=〃1.0〃encoding="utf-8"?〉

<LinearLayoutxmlns:android=,,http://schemas.android/apk/res/android〃

android:layout_width=,,fill_parent,,

android:layout_height二〃fill_parent,/

android:orientation=z,verticar,>

<TextView

android:id二"@+id/1extv:ew〃

android:layout_width=,,fi1l_parent”

android:layoutheight="wrapcontent”

android:text=/z@string/hello_world/z/>

<CheckBox

android:id=z,@+id/checkboxr

android:layout.jvidt.h=z,fi1l_parent/z

androidlayoutheight二,Tapcontent”

android:text=,/?string/CheckBoxr,>

</CheckBox>

<CheckBox

android:id=〃@+id/checkbox2”

android:layoujwidth="fi1l_parent〃

android:layout_height=*wrap_contentz,

android:text=〃@string/CheckBox2〃>

</CheckBox>

<CheckBox

android:id=,,@+id/checkbox3z,

android:1ayout_width=*fi11_parent”

android:1ayout_height=*wrap_content

android:text="@string/CheckBox3〃>

</CheckBox>

<CheckBox

android:id=,,@+id/checkbox4?z

android:layout_width="zfillparent^

android:layoutheight=*wrap_content”

android:text=,,@string/CheckBox4,/>

</CheckBox>

<Button

android:id="@+id/hutton1〃

android:layout_width=,,wrapcontent”

android:layoutheight=vwrap_content,,

android:text二〃提交〃>

</Button>

</LinearLayout>

string.xml

<?xmlversion=T.0〃encoding二〃utf-8”?〉

(resources)

(stringname二〃appname,,>Lab</string>

<stringname-,,action_settings,/>Settings</string>

(stringname二〃hello_world"〉Helloworld!</string>

(stringname=*CheckBoxl/z>swim</string>

(stringname=,,CheckBox2,,>run</string>

(stringname=,,CheckBox3,,>dance</string>

<stringname=,,CheckBox4,,>walk</string>

</rescurces>

96.設(shè)計(jì)加減法計(jì)算器。

要求:程序包括兩個(gè)頁面第一個(gè)頁面主要包括兩個(gè)文本編輯框,用于輸入兩個(gè)操作數(shù)輸入操作數(shù)后,單

擊系統(tǒng)的亞NU按鈕,會(huì)彈出Menu菜單,Menu菜單包括“相加”、“相減”和“退出”三個(gè)按鈕,當(dāng)點(diǎn)擊

“相加”按鈕會(huì)對(duì)兩個(gè)操作數(shù)執(zhí)行加法,當(dāng)點(diǎn)擊“相減”按鈕時(shí),會(huì)對(duì)兩個(gè)操作數(shù)執(zhí)行減法,在另一個(gè)頁面

會(huì)顯示計(jì)算結(jié)果。

MainActivity.java:

packagecom.example,wpp201942577four;

importandroid.app.Activity;

importandroid.content.Intent;

importandroid,os.Bundle;

importandroid,view.Menu;

importandroid,view.Mcnultem;

importandroid,view.View;

importandroid,view.View.OnClickListener;

import,android,widget.Button;

importandroid,widget.EditText;

importandroid,widget.TextView;

publicclassMainActivityextendsActivity{

Calledwhentheactivityisfirstcreate;d.*/

privateEditTextfactorOne;

privateEditTextfactorTwo;

privateTextViewsymbol;

privateButtoncalculate;

0Cverride

publicvoidonCreate(BundlesavedlnstanceState){

super.onCreate(savedlnstanceState);

setContentView(R.layout,main);

factorOne=(EditText)findViewById(R.id.factorOne)\

factorTwo=(EditText)findViewById(R.id.factorTw6);

symbol=(TextView)findViewRyTd(R.id.symbol);

symbol.setText(R.string,symbol);

?Override

publicbooleanonCreateOptionsMenu(Menumenu){

menu.add(0,1,1,R.string,exit);

menu,add(0,2,2,R.string,add);

menu.add(0,3,3,R.string.sul));

returnsuper.onCreateOptionsMenu(menu);

publicvoidaddO{

StringfactorOneStr二factorOne.getTextO.toStringO;

StringfactorTwoStr-factorTwo.getTextO.toStringO;

Intentintent=newIntent();

,,,,

intent.putExtra(one)factorOneStr);

,/,,

intent.putExtra(two)factorTwoStr);

intent.putExtra("three","+〃);

intent.setClass(MainActivity.this,ResultActiviiy.class);

startActivity(intent);

publicvoidsub(){

StringfactorOneStr=factorOne.getTextO.toStringO;

StringfactorTwoStr=factorTwo.getTextO,toStringO;

Intentintent=newIntent();

intent.putExtra("one",factorOneStr);

,,,,

intent.putExtra(two)factorTwoStr);

int.ent..putExtra("three”,;

intent.setClass(MainActivity.this,ResultActiviiy.class);

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論