はあなたがここにサービス を学ばなければならない遠くに最初に行かない新しいクラスを作成し、Exmapleのためにそれをネームサービス
の例である:MyServiceで
public class MyService extends Service {
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
return Null;
}
@Override
public void onCreate() {
Toast.makeText(this, "The new Service was Created", Toast.LENGTH_LONG).show();
}
@Override
public void onStart(Intent intent, int startId) {
// For time consuming an long tasks you can launch a new thread here...
// Do your Bluetooth Work Here
Toast.makeText(this, " Service Started", Toast.LENGTH_LONG).show();
}
@Override
public void onDestroy() {
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
}
単に活動を開始しますこの
を書く停止するにはあなたの主な活動
startService(new Intent(this, MyService.class));
にこの行を書きます
stopService(new Intent(this, MyService.class));
この訪問 http://www.javacodegeeks.com/2014/01/android-service-tutorial.html