android serice 实例

package irdc.ex06_04;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class EX06_04 extends Activity
{
private Button mButton01,mButton02;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mButton01 = (Button)findViewById(R.id.myButton1);

/* 开始启动系统服务按钮事件 */
mButton01.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub

/* 建构Intent对象,指定开启对象为mService1服务 */
Intent i = new Intent( EX06_04.this, mService1.class );

/* 设定新TASK的方式 */
i.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );

/* 以startService方法启动Intent */
startService(i);
}
});

mButton02 = (Button)findViewById(R.id.myButton2);

/* 关闭系统服务按钮事件 */
mButton02.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub

/* 构造Intent对象,指定欲关闭的对象为mService1服务 */
Intent i = new Intent( EX06_04.this, mService1.class );

/* 以stopService方法关闭Intent */
stopService(i);
}
});
}
}

更多相关文章

  1. android 判断service是否开启
  2. android 键盘关闭/显示
  3. android之location01
  4. Android(安卓)学习笔记--android――Activity学习
  5. android之蓝牙操作(二)
  6. init.rc
  7. Android之辅助服务下篇————AccessibilityServic源码分析
  8. Android(安卓)神兵利器Dagger2使用详解(三)MVP架构下的使用
  9. Android开发中 AndroidManifest.xml配置之service,receiver标签配

随机推荐

  1. Android--recycleview滚动条
  2. Android系统自带样式
  3. Android(安卓)使用 TableLayout 布局拉伸
  4. Android(安卓)EditText各种属性及作用
  5. Android(安卓)textAppearance的属性设置
  6. Android应用开发——系统自带样式Android
  7. Gridview的stretchMode详解附自动宽度
  8. 计算器布局基于GridLayout
  9. Android(安卓)圆角矩形
  10. 《Android实例剖析笔记》系列文章