WEB开发网
开发学院手机开发Android 开发 实例示范如何使用 Android Services 阅读

实例示范如何使用 Android Services

 2010-03-03 15:48:00 来源:WEB开发网   
核心提示:import android.content.Intent;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.

import android.content.Intent;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class ServicesDemo extends Activity implements OnClickListener {

private static final String TAG = “ServicesDemo”;

Button buttonStart, buttonStop;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

buttonStart = (Button) findViewById(R.id.buttonStart);

buttonStop = (Button) findViewById(R.id.buttonStop);

buttonStart.setOnClickListener(this);

buttonStop.setOnClickListener(this);

}

public void onClick(View src) {

switch (src.getId()) {

case R.id.buttonStart:

Log.d(TAG, “onClick: starting srvice”);

startService(new Intent(this, MyService.class));

break;

case R.id.buttonStop:

Log.d(TAG, “onClick: stopping srvice”);

stopService(new Intent(this, MyService.class));

break;

}

}

}

package com.example;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class ServicesDemo extends Activity implements OnClickListener {

private static final String TAG = “ServicesDemo”;

Button buttonStart, buttonStop;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

上一页  1 2 3 4 5  下一页

Tags:实例 示范 如何

编辑录入:coldstar [复制链接] [打 印]
赞助商链接