项目中Service使用
来源:互联网 发布:三菱编程器型号 编辑:程序博客网 时间:2024/05/16 02:01
1、
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="s.s.t"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".Broacast" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /><!-- 系统启动 -->
<action android:name="android.intent.action.SIG_STR" /><!-- 电话的信号强度已经改变 -->
<action android:name="android.intent.action.CONFIGURATION_CHANGED" /><!-- 设备的配置信息已经改变 -->
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
<action android:name="android.net.conn.BACKGROUND_DATA_SETTING_CHANGED" />
</intent-filter>
</receiver>
<service android:name=".ServiceTest"></service>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
2、
package s.s.t;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnStart = (Button)this.findViewById(R.id.buttonstart);
Button btnEnd = (Button)this.findViewById(R.id.buttonstop);
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,ServiceTest.class);
startService(intent);
}
});
btnEnd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,ServiceTest.class);
stopService(intent);
}
});
}
}
3、
package s.s.t;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class Broacast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent intente = new Intent(context,ServiceTest.class);
context.startService(intente);
}
}
4、
package s.s.t;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class ServiceTest extends Service {
private int tag = 1;
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Log.e("ServiceTest", "onCreate");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
Log.e("ServiceTest", tag+"");
tag = tag+1;
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
Log.e("ServiceTest", "onDestroy");
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
- 项目中Service使用
- Service中使用AlertDialog
- spring项目中使用监听器时获取spring中注入的service
- spring项目中使用监听器时获取spring中注入的service
- [置顶]Android 项目开发 基于Web Service 服务的中英翻译软件(四)使用Sqlite “辅助” Web Service
- (4.3.1.2)【项目一】主体框架Fragment中启动Service与notification的使用
- Handler: Service中使用Toast
- service中使用自定义dialog
- android中为什么使用service?
- Handler: Service中使用Toast
- 在Service中使用Toast
- Android中service的使用
- Handler: Service中使用Toast
- android中Service使用详解
- android中Service使用startService
- Android中Service使用bindService
- Android中Service的使用
- MyEclipse中使用Web Service
- Project——采用服务实现电话窃听器
- textblock通过LineHeight的调整来改变行距
- display:none与visible:hidden的区别
- Project——建立能与服务通信的应用与服务的生命周期
- sigset_t结构体
- 项目中Service使用
- 国嵌视频学习---linux内核启动流程
- 面向对象
- Hadoop 集群常见错误
- DAPM之二:audio paths与dapm kcontrol
- partition by 的用法
- eclipse中字体设置
- C# 字符串转化为时间格式
- LINUX内核编译方法以及其步骤(在READ HAT LINUX 5.0上面运行成功)