バックグラウンドで実行されるサービスが必要で、30 ~ 120 秒後に起動し、デバイスの場所を見つけ、その場所をデータ センターに送信してスリープ状態になります。再び 30 ~ 120 秒後にサービスが起動し、場所を特定しますそして眠りにつく。サービスを手動で開始および停止できますが、開始 (30 ~ 120 秒) してサービスを自動的に停止する必要があります。
So,My question is how can i start and stop the service automatically?
ご提案いただきありがとうございます。
私のコードは
public class Service extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button start = (Button)findViewById(R.id.startButton);
Button stop = (Button)findViewById(R.id.stopButton);
start.setOnClickListener(startListener);
stop.setOnClickListener(stopListener);
}
private OnClickListener startListener = new OnClickListener() {
public void onClick(View v){
startService(new Intent(Service.this,SimpleService.class));
}
};
private OnClickListener stopListener = new OnClickListener() {
public void onClick(View v){
stopService(new Intent(Service.this,SimpleService.class));
}
};
}