2022年安卓实验报告.pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《2022年安卓实验报告.pdf》由会员分享,可在线阅读,更多相关《2022年安卓实验报告.pdf(18页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、安卓实验报告班级: xxxxx学号:姓名: xxxx实验一: Activity生命周期的测试精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 1 页,共 18 页 - - - - - - - - - - 一:实验目的掌握使用 Eclipse开发 Android应用开发程序的方法;掌握 Android虚拟设备的创建方法;了解 Android的程序结构;了解使用命令行创建Android程序方法;了解Activity生命周期,理解Activity事件回调,onRestoreInstanceState()和onSa
2、veInstanceState两个函数的使用。二:实验设备 Eclipse 开发 Android 应用 Android虚拟设备( AVD)三:实验内容(1)正常启动ActivityLife,然后单击用户界面的“结束程序”按钮关闭程序。(2)正常启动ACtivityLife,然后通过“拨号键”启动内置的拨号程序,再通过“回退建”退出拨号程序,使ActivityLife重新显示在屏幕中。四:实验核心代码packageclass MainActivity extends Activity privatestatic String TAG=LIFECYCLE;Overrideprotectedvoid
3、 onCreate(Bundle savedInstanceState) (savedInstanceState); setContentView (TAG, (1) onCreate(); Button button =(Button) findViewById (new OnClickListener() publicvoid onClick(View view) oString().trim();String str1 = ().toString().trim();( 姓名: +str);( 爱好: +str1);if (arg1 = ( 性别:+ 男);else if (arg1 =
4、( 性别: +女); ););五:运行结果截图:精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 2 页,共 18 页 - - - - - - - - - - 实验三:不同界面的切换一:实验目的掌握各种界面布局的特点和使用方法;掌握选项菜单,子菜单和快捷菜单的使用方法。二; 实验设备 Eclipse 开发 Android 应用 Android虚拟设备( AVD)三; 实验内容:设计一个Tab 标签页,实现LinearLayout,RelativeLayout, AbsoluteLayout三种分页面之间的切
5、换,每个页面的内容包括用户名和确定,取消两个按钮四:实验核心代码:: public class MainActivity extends TabActivity protected void onCreate(Bundle savedInstanceState) (savedInstanceState); setContentView TabHost tabHost=getTabHost(); (this).inflate (),true); (this).inflate (),true); (this).inflate (),true); (TAB1).setIndicator(线性布局 )
6、.setContent (TAB1).setIndicator(绝对布局 ).setContent (TAB1).setIndicator(相对布局 ).setContent Tab1,javapublic class Tab1 extends Activity public void onCreate(Bundle savedInstanceState) (savedInstanceState);setContentView 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 3 页,共 18 页 - -
7、- - - - - - - - public class Tab2 extends Activity public void onCreate(Bundle savedInstanceState)(savedInstanceState);setContentView public class Tab3 extends Activity public void onCreate(Bundle savedInstanceState)(savedInstanceState);setContentView 五:运行结果截图:实验四:登陆界面和广播消息一:实验目的了解使用Intent进行组件通信的原理;
8、了解 Intent过滤器的原理与匹配机制;掌握发送和接受广播消息的方法。二:实验设备 Eclipse 开发 Android 应用 Android虚拟设备( AVD)三:实验内容先写一个登陆界面,包括用户名,密码,点击登陆时实现页面的跳转功能,在第二个页面使用 Intent发送消息,并调用sendBroadcast ()函数把Intent携带的消息传送出去,用 BroadcastReceiver接受广播消息,在页面下方显示广播内容。四; 实验核心代码:publicclass MainActivity extends Activity 精品资料 - - - 欢迎下载 - - - - - - - -
9、 - - - 欢迎下载 名师归纳 - - - - - - - - - -第 4 页,共 18 页 - - - - - - - - - - private Button button ;Overrideprotectedvoid onCreate(Bundle savedInstanceState) (savedInstanceState); setContentView button =(Button) findViewById (new () publicvoid onClick(View arg0) Intent intent=new Intent,; startActivity(inte
10、nt);); publicclass Second extends Activity private Button button2 ;private EditText editText;protectedvoid onCreate(Bundle savedInstanceState) (savedInstanceState);setContentView Intent intent=getIntent();editText=(EditText) findViewById button2 =(Button) findViewById(new () publicvoid onClick(View
11、arg0) Intent intent=new Intent( );(message , ().toString();sendBroadcast(intent);); publicclass MyBroadcastReceiver extends BroadcastReceiverpublicvoid onReceive(Context context, Intent intent) String msg=(message );(context, msg, .show();五:运行结果截图精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - -
12、 - - - - - - -第 5 页,共 18 页 - - - - - - - - - - 实验五: Service绑定实现数据运算一:实验目的了解 Service的原理和用途;掌握本地服务的管理和方法;掌握服务的隐式启动和显示启动方法;掌握远程服务的绑定和调用方法。二:实验设备 Eclipse 开发 Android 应用 Android虚拟设备( AVD)三: 实验内容以绑定方式使用Service ,获取 Service实例,当点击绑定服务时可以实现两个数的求差和比较大小功能,并输出结果,当点击取消绑定服务时,则无法运算。四:实验核心代码publicclass MathService ex
13、tends Serviceprivatefinal IBinder mBinder =new LocalBinder();publicclass LocalBinder extends Binder MathService getService()return ; public IBinder onBind(Intent intent) ( this , 本地绑定 :MathService,.show();returnmBinder ; publicboolean onUnbind(Intent intent)( this , 取消本地绑定:MathService, .show();retur
14、nfalse ; publiclong sub( long a, long b)return a-b; 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 6 页,共 18 页 - - - - - - - - - - publicint compare( long a, long b)if (ab) return 1;elseif (a=b) return 0;elsereturn -1;publicclass MainActivity extends Activity private MathService
15、 mathService ;private Button button1 ;private Button button2 ;private Button button3 ;private Button button4 ;private EditText editText1;private EditText editText2;private EditText editText3;privatebooleanisBound =false ;Overrideprotectedvoid onCreate(Bundle savedInstanceState) (savedInstanceState);
16、 setContentView editText1=(EditText) findViewById editText2=(EditText) findViewById editText3=(EditText) findViewById button1 =(Button) findViewById button2 =(Button) findViewById button3 =(Button) findViewById button4 =(Button) findViewById (new () publicvoid onClick(View v) if (! isBound )final In
17、tent serviceIntent=new Intent (,; bindService(serviceIntent, mConnection , ;isBound =true ; ); (new () publicvoid onClick(View v) if ( isBound )isBound =false ; unbindService(mConnection );mathService =null ; 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 7 页,共 18 页 - - - - - -
18、 - - - - ); (new () publicvoid onClick(View v) if ( mathService =null )( 未绑定服务 );return ;String a = ().toString();long a1 = (a);String b = ().toString();long b1 = (b);long result=(a1, b1);String msg=(a1)+- +(b)+= +(result);(msg);); (new () publicvoid onClick(View v) if ( mathService =null )( 未绑定服务 )
19、;return ;String a = ().toString();long a1 = (a);String b = ().toString();long b1 = (b);long result=(a1, b1);if (result=1)(a+ +b);elseif (result=0)(a+ = +b);else (a+ +b); ); 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 8 页,共 18 页 - - - - - - - - - - private ServiceConnection m
20、Connection =new ServiceConnection() publicvoid onServiceDisconnected(ComponentName arg0) mathService =null ;publicvoid onServiceConnected(ComponentName name, IBinder service) mathService =(service).getService(); 实验六: SQLite 实现用户的增删改查一:实验目的了解 SQLite 数据库的特点和体系及结构;掌握 SQLite 数据库的建立和操作方法;理解 ContentProvid
21、e的用途和原理;掌握 ContentProvider的创建和使用方法。二:实验设备 Eclipse 开发 Android 应用 Android虚拟设备( AVD)三: 实验内容使用 SQlite数据库实现用户(包括:姓名,年龄,身高)的添加数据,全部显示,清除显示,全部删除,ID 删除, ID 查询, ID 更新的功能。四:实验核心代码publicclass MainActivity extends ActionBarActivity private EditText et_name;private EditText et_sex ;private EditText et_department
22、;private EditText et_id ;private EditText et_salary;private MyOpenHelper oh;private SQLiteDatabase db;private TextView tv ;private LinearLayout ll ;精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 9 页,共 18 页 - - - - - - - - - - Overrideprotectedvoid onCreate(Bundle savedInstanceS
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022 年安卓 实验 报告
![提示](https://www.deliwenku.com/images/bang_tan.gif)
限制150内