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);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
service.rar (84个子文件)
StadyService
.project 848B
src
lovefang
stadyService
UseAsyncTask.java 2KB
UseBroadcast.java 1KB
UseHandleMessage.java 2KB
UseNotification.java 4KB
UseBroadcastReceiver.java 388B
UseVibrator.java 2KB
UseBrider.java 1KB
CountService.java 1KB
MainStadyServics.java 6KB
UseBriderFace.java 823B
UseActionCall.java 1KB
UseAlarmManager.java 1KB
UsePhoneState.java 5KB
AndroidManifest.xml 2KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
drawable-mdpi
icon.png 3KB
layout
use_vibrator.xml 839B
use_async.xml 695B
use_action_call.xml 663B
notification.xml 1KB
usealarmmanager.xml 570B
broadcast.xml 411B
use_handleandmessage.xml 456B
usephonestate.xml 663B
main.xml 2KB
values
strings.xml 179B
assets
gen
lovefang
stadyService
R.java 3KB
default.properties 364B
.classpath 280B
bin
resources.ap_ 17KB
lovefang
stadyService
R$layout.class 700B
MainStadyServics$9.class 1KB
UseNotification$1.class 2KB
UseNotification$2.class 1KB
UseBroadcast$1.class 1KB
UseAlarmManager$1.class 1KB
UseAlarmManager$2.class 952B
R$drawable.class 409B
R$attr.class 349B
UseBroadcastReceiver.class 701B
UseVibrator$2.class 936B
UseAsyncTask.class 1KB
MainStadyServics$4.class 1KB
UseBroadcast.class 1KB
UseBriderFace.class 1KB
UsePhoneState.class 2KB
MainStadyServics$10.class 1KB
UseNotification$4.class 1KB
UseNotification$5.class 910B
MainStadyServics$7.class 1KB
MainStadyServics$6.class 1KB
MainStadyServics$2.class 1KB
MainStadyServics$8.class 1KB
UsePhoneState$1.class 4KB
UseNotification$3.class 1KB
UseBrider.class 1KB
UseHandleMessage$2.class 1KB
UseVibrator$3.class 958B
UseVibrator$1.class 915B
R$id.class 1KB
UseActionCall.class 1KB
CountService$1.class 1KB
UseNotification.class 2KB
MainStadyServics$3.class 1KB
UseActionCall$1.class 2KB
MainStadyServics$5.class 1KB
MainStadyServics$11.class 1KB
R.class 552B
R$string.class 436B
UseHandleMessage.class 2KB
UseBrider$1.class 1KB
UseAlarmManager.class 2KB
CountService$ServiceBinder.class 649B
CountService.class 1KB
UseAsyncTask$1.class 1008B
MainStadyServics.class 4KB
UseVibrator.class 2KB
MainStadyServics$1.class 1KB
UseHandleMessage$1.class 1KB
UseAsyncTask$LoadTast.class 3KB
StadyService.apk 31KB
classes.dex 28KB
共 84 条
- 1
BruceZhang
- 粉丝: 3047
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页