要求:
1.实验报告要完整,即要有实验要求与目的、实验内容与步骤(必要流程图或活动图、代码)、运行结果与分析、实验体会与收获;
2.代码要有必要的注释;
3.标题为四号黑体,其他为宋体小四号,行间距为单倍行间距,纸张大小为A4;
4.考核项目
考核项目 |
格式与完成性 |
实验内容 |
实验结果与分析 |
实验体会与收获 |
总成绩 |
权重 |
20% |
60% |
10% |
10% |
100% |
得分 |
-
实验目的
1.了解服务的概述,能够说出什么是服务;
2.掌握服务的创建方式,能够独立创建一个服务;
3. 熟悉服务的生命周期,能够阐述服务生命周期中的方法;
4.掌握服务的两种启动方式,能够实现服务的启动与关闭功能;
5.掌握服务的通信,能够完成仿网易音乐播放器案例。
。
-
实验工具
Android studio。
-
实验内容
运行效果图如下:
-
完成上图的布局;
-
点击“播放”按钮、“暂停”按钮、“继续”按钮完成相应功能。
-
实验过程(含代码)
activity_main.xml: <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/music_bg"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="160dp">
<RelativeLayout
android:layout_width="300dp"
android:layout_height="70dp"
android:id="@+id/rl_title"
android:layout_centerHorizontal="true"
android:background="@drawable/title_bg"
android:gravity="center_horizontal"
android:paddingLeft="80dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_music_title"
android:layout_marginTop="8dp"
android:text="体面"
android:textSize="12sp"
android:textStyle="bold"
android:textColor="@color/black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height