package lovefang.stadyService;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.content.Intent;
import android.util.Log;
/**这是使用后台服务的学习例子*/
public class MainStadyServics extends Activity {
/**参数设置*/
Button startServiceButton;// 启动服务按钮
Button shutDownServiceButton;// 关闭服务按钮
Button startBindServiceButton;// 启动绑定服务按钮
Button sendBroadcast;// 使用广播
Button notificationButton;// 使用通知功能
Button alarmButton;// 使用闹钟
Button handlerButton;// 使用handler
Button asyncButton;// 使用异步加载
Button phoneStateButton;// 查看手机状态
Button callphoneButton;// 拨打电话
Button vibratorButton;// 使用震动
CountService countService;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("MainStadyServics", "setContentView");
setContentView(R.layout.main);
getWidget();
regiestListener();
}
/**获得组件*/
public void getWidget(){
startServiceButton = (Button)findViewById(R.id.startServerButton);
startBindServiceButton = (Button)findViewById(R.id.startBindServerButton);
shutDownServiceButton = (Button)findViewById(R.id.sutdownServerButton);
sendBroadcast = (Button)findViewById(R.id.sendBroadcast);
notificationButton = (Button)findViewById(R.id.notification);
alarmButton = (Button)findViewById(R.id.alarm);
handlerButton = (Button)findViewById(R.id.handler);
asyncButton = (Button)findViewById(R.id.async);
phoneStateButton = (Button) findViewById(R.id.phonestate);
callphoneButton = (Button) findViewById(R.id.callphone);
vibratorButton = (Button) findViewById(R.id.vibrator);
}
/**为按钮添加监听*/
public void regiestListener(){
startServiceButton.setOnClickListener(startService);
shutDownServiceButton.setOnClickListener(shutdownService);
startBindServiceButton.setOnClickListener(startBinderService);
sendBroadcast.setOnClickListener(broadcastReceiver);
notificationButton.setOnClickListener(notification);
alarmButton.setOnClickListener(startAlarm);
handlerButton.setOnClickListener(handler);
asyncButton.setOnClickListener(async);
phoneStateButton.setOnClickListener(phonestate);
callphoneButton.setOnClickListener(callphoneEvent);
vibratorButton.setOnClickListener(vibrator);
}
/**启动服务的事件监听*/
public Button.OnClickListener startService = new Button.OnClickListener(){
public void onClick(View view){
/**单击按钮时启动服务*/
Intent intent = new Intent(MainStadyServics.this,CountService.class);
startService(intent);
Log.v("MainStadyServics", "start Service");
}
};
/**关闭服务*/
public Button.OnClickListener shutdownService = new Button.OnClickListener(){
public void onClick(View view){
/**单击按钮时启动服务*/
Intent intent = new Intent(MainStadyServics.this,CountService.class);
/**退出Activity是,停止服务*/
stopService(intent);
Log.v("MainStadyServics", "shutDown serveice");
}
};
/**打开绑定服务的Activity*/
public Button.OnClickListener startBinderService = new Button.OnClickListener(){
public void onClick(View view){
/**单击按钮时启动服务*/
Intent intent = new Intent(MainStadyServics.this,UseBrider.class);
startActivity(intent);
Log.v("MainStadyServics", "start Binder Service");
}
};
/**打开广播学习的按钮*/
public Button.OnClickListener broadcastReceiver = new Button.OnClickListener(){
public void onClick(View view){
Intent intent = new Intent(MainStadyServics.this,UseBroadcast.class);
startActivity(intent);
Log.v("MainStadyServics","start broadcast");
}
};
/**打开通知*/
public Button.OnClickListener notification = new Button.OnClickListener(){
public void onClick(View view){
Intent intent = new Intent(MainStadyServics.this, UseNotification.class);
startActivity(intent);
Log.v("MainStadyService ","start Notification");
}
};
/**使用闹钟*/
public Button.OnClickListener startAlarm = new Button.OnClickListener(){
public void onClick(View view){
Intent intent = new Intent(MainStadyServics.this, UseAlarmManager.class);
startActivity(intent);
Log.v("MainStadyService ","start alarm");
}
};
public Button.OnClickListener handler= new Button.OnClickListener(){
public void onClick(View view){
Intent intent = new Intent(MainStadyServics.this, UseHandleMessage.class);
startActivity(intent);
Log.v("MainStadyService ","start handle");
}
};
public Button.OnClickListener async= new Button.OnClickListener(){
public void onClick(View view){
Intent intent = new Intent(MainStadyServics.this, UseAsyncTask.class);
startActivity(intent);
Log.v("MainStadyService ","start handle");
}
};
public Button.OnClickListener phonestate= new Button.OnClickListener(){
public void onClick(View view){
Intent intent = new Intent(MainStadyServics.this, UsePhoneState.class);
startActivity(intent);
Log.v("MainStadyService ","start phonestate");
}
};
public Button.OnClickListener callphoneEvent= new Button.OnClickListener(){
public void onClick(View view){
Intent intent = new Intent(MainStadyServics.this, UseActionCall.class);
startActivity(intent);
Log.v("MainStadyService ","start callphone");
}
};
public Button.OnClickListener vibrator= new Button.OnClickListener(){
public void onClick(View view){
Intent intent = new Intent(MainStadyServics.this, UseVibrator.class);
startActivity(intent);
Log.v("MainStadyService ","start callphone");
}
};
/***/
protected void onDestroy(){
super.onDestroy();
Intent intent = new Intent(MainStadyServics.this,CountService.class);
/**退出Activity是,停止服务*/
stopService(intent);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
一个Demo学习Android中所有的Service
共84个文件
class:50个
java:14个
xml:11个
5星 · 超过95%的资源 需积分: 10 43 下载量 81 浏览量
2013-03-28
14:19:48
上传
评论 1
收藏 117KB RAR 举报
温馨提示
这个例子包含了Android开发中常用到的Service,是学习Service的典例
资源推荐
资源详情
资源评论
收起资源包目录
service.rar (84个子文件)
StadyService
bin
classes.dex 28KB
lovefang
stadyService
UseBrider.class 1KB
MainStadyServics$1.class 1KB
CountService.class 1KB
UseAlarmManager$1.class 1KB
UseNotification.class 2KB
MainStadyServics$5.class 1KB
R$layout.class 700B
R$id.class 1KB
R$drawable.class 409B
MainStadyServics$2.class 1KB
MainStadyServics$7.class 1KB
UseNotification$5.class 910B
UsePhoneState.class 2KB
UseBroadcastReceiver.class 701B
MainStadyServics.class 4KB
UseAlarmManager.class 2KB
UseBroadcast.class 1KB
UseNotification$2.class 1KB
UseHandleMessage.class 2KB
UseHandleMessage$1.class 1KB
UseVibrator$2.class 936B
R$attr.class 349B
UseBriderFace.class 1KB
MainStadyServics$9.class 1KB
R.class 552B
UsePhoneState$1.class 4KB
MainStadyServics$6.class 1KB
MainStadyServics$3.class 1KB
UseNotification$3.class 1KB
UseNotification$1.class 2KB
UseHandleMessage$2.class 1KB
UseActionCall$1.class 2KB
UseNotification$4.class 1KB
UseVibrator$3.class 958B
UseAsyncTask$LoadTast.class 3KB
R$string.class 436B
UseAlarmManager$2.class 952B
UseBroadcast$1.class 1KB
UseVibrator$1.class 915B
CountService$1.class 1KB
MainStadyServics$10.class 1KB
MainStadyServics$4.class 1KB
UseBrider$1.class 1KB
UseVibrator.class 2KB
MainStadyServics$11.class 1KB
UseAsyncTask$1.class 1008B
CountService$ServiceBinder.class 649B
UseAsyncTask.class 1KB
MainStadyServics$8.class 1KB
UseActionCall.class 1KB
resources.ap_ 17KB
StadyService.apk 31KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
values
strings.xml 179B
drawable-mdpi
icon.png 3KB
layout
use_action_call.xml 663B
use_handleandmessage.xml 456B
notification.xml 1KB
use_vibrator.xml 839B
use_async.xml 695B
usephonestate.xml 663B
main.xml 2KB
broadcast.xml 411B
usealarmmanager.xml 570B
assets
default.properties 364B
gen
lovefang
stadyService
R.java 3KB
src
lovefang
stadyService
UseBrider.java 1KB
UseBroadcastReceiver.java 388B
UseHandleMessage.java 2KB
UseAlarmManager.java 1KB
UseActionCall.java 1KB
CountService.java 1KB
UseNotification.java 4KB
UseBriderFace.java 823B
UseBroadcast.java 1KB
UsePhoneState.java 5KB
UseAsyncTask.java 2KB
MainStadyServics.java 6KB
UseVibrator.java 2KB
.project 848B
.classpath 280B
AndroidManifest.xml 2KB
共 84 条
- 1
资源评论
- CLATZJ2014-03-02支持下谢谢了
aicrystal
- 粉丝: 1
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 31-31.渗透测试SQL注入盲注
- 老板必备实体门店超常规营销获客,218套实体店落地方案解析-课程网盘链接提取码下载 .txt
- 基于Python+Flask+MySQL+SWPU数据库原理开发最流行的外卖订餐系统+源码+开发文档(高分优秀项目)
- ESG的同群效应数据集(2010-2022年).xlsx
- 华为OD机试机考题库Go语言实现36道题(含题目描述、详细解题报告).zip
- 新能源锂电池行业创业的财富方案,锂电池回收高阶课-课程网盘链接提取码下载 .txt
- 30-30.渗透测试SQL注入基础(下)、工具和POST类型(上)
- ssm(老年公寓管理系统)
- TP179-V1.1.2-51单片机蓝牙遥控车.zip
- auto-sqladmin
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功