Service1
来源:互联网 发布:班班软件下载 编辑:程序博客网 时间:2024/06/06 20:25
原来 service 是指界面被关掉 还能继续运行的意思,运行在后台。
startservice
stopservice
绑定服务(关闭界面,会退出当前的app)
bindservice
unbindservice
基本用法如下:
package zhbit.test;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class Using_ServiceActivity extends Activity implements OnClickListener, ServiceConnection {
/* Called when the activity is first created. /
private Button btnstartservice, btnstopservice, btnbindservice,
btnunbindservice;
private Intent intent1;
@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); intent1 = new Intent(Using_ServiceActivity.this, Second.class); btnstartservice = (Button) findViewById(R.id.StartService); btnstopservice = (Button) findViewById(R.id.stopService); btnbindservice = (Button) findViewById(R.id.BindService); btnunbindservice = (Button) findViewById(R.id.UnBindService); btnstartservice.setOnClickListener(this); btnstopservice.setOnClickListener(this); btnbindservice.setOnClickListener(this); btnunbindservice.setOnClickListener(this);}public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.StartService: startService(intent1); break; case R.id.stopService: stopService(intent1); break; case R.id.BindService: bindService(intent1, this, Context.BIND_AUTO_CREATE); break; case R.id.UnBindService: unbindService(this); // stopService(intent1); break; default: break; }}public void onServiceConnected(ComponentName name, IBinder service) { // TODO Auto-generated method stub Toast.makeText(this, "onserviceconnected", Toast.LENGTH_LONG).show();}public void onServiceDisconnected(ComponentName name) { // TODO Auto-generated method stub Toast.makeText(this, "onservicedisconnected", Toast.LENGTH_LONG).show();}
}
package zhbit.test;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.widget.Toast;
public class Second extends Service{
@Overridepublic void onCreate() { Toast.makeText(this, "onCreate", Toast.LENGTH_LONG).show(); System.out.print("onCrate"); super.onCreate();}@Overridepublic void onDestroy() { Toast.makeText(this, "onDestroy", Toast.LENGTH_LONG).show(); System.out.print("onDestroy"); super.onDestroy();}private final EchServiceBinder echservicebinder = new EchServiceBinder();public class EchServiceBinder extends Binder{}@Overridepublic IBinder onBind(Intent intent) { Toast.makeText(this, "onBind", Toast.LENGTH_LONG).show(); return echservicebinder;}
}
- Service1
- Service1
- axis2创建web service1
- Android学习--Service1
- android初接触之service1
- c#webservice 分析器错误信息: 未能创建类型“Service1”。
- c#webservice 分析器错误信息: 未能创建类型“Service1”
- android双后台服务,消息通知类(service1)
- android--Service1(service不是一个单独的进程,也不是一个线程)
- 无法激活请求的服务“http://localhost:10582/Service1.svc?wsdl”
- WCF中 改名后 无法找到 ServiceHost 指令中作为服务属性值提供的类型“WCFDemo.Service1”。
- Property Animation属性动画,还用补间动画你就out了
- android颜色
- 不同技能的测试工程师是如何正确的进行自动化测试
- 1.5.5 HTML表单处理
- 去掉UIWebView底部的黑条
- Service1
- 关于烂代码的那些事(上)
- 转: CvMat,Mat和IplImage之间的转化和拷贝
- 正则表达式:Notepad++查找两段特殊字符之间文字并在该目标字符后面添加字符
- PHP的异步并行网络扩展swoole
- Eigen vector and eigen value
- 并发无锁环形队列的实现
- 【算法学习】Fast burst images denoising
- Factory pattern