Service分类,生命周期,普通方式启动
2016-06-27 14:52
441 查看
package com.example.lenovo.service; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.IBinder; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } //普通方式启动 public void bt_1(View v) { //准备Intent:显式意图 Intent intent = new Intent(this,MyService.class); intent.putExtra("test","发送的数据"); //启动Service startService(intent); Toast.makeText(MainActivity.this, "Service已启动", Toast.LENGTH_SHORT).show(); } //普通方式关闭 public void bt_2(View v) { //准备Intent:显式意图 Intent intent = new Intent(this,MyService.class); //关闭Service stopService(intent); Toast.makeText(MainActivity.this, "Service已停止", Toast.LENGTH_SHORT).show(); }
java
继承于Service,并在AndroidManifest中注册
相关文章推荐
- 表空间回收操作判断
- [转]Unity目录在各平台路径
- asp.net form 验证方式的使用(转载)
- 记一次失败的电话面试
- Python使用smtplib模块发送电子邮件的流程详解
- BZOJ1098: [POI2007]办公楼biu
- JavaScript:继承方式
- IOS_ios逆向工程-静态分析
- react-native 环境配置及hello world
- java环境变量如何配置
- Log Parser 2.2 分析 IIS 日志
- cmake编译win下64位obs
- php中的cookie用法
- asp.net下通过泛解析和伪静态实现二级域名的实现方法
- JAVA_Android APK反编译就这么简单 详解(附图)
- vmware workstation ubuntu虚拟机无法使用共享目录
- zabbix 监控nginx
- 社会化商业平台能否为转型指明方向
- 浪潮集团执行总裁王兴山:企业管理软件领域也要供给侧改革
- water-and-jug-problem