Temporizador do processo em segundo plano no android
Estou tentando obter um cronômetro de processo para executá-lo e mantê-lo em execução em segundo plano no android (começa com um clique no botão).
O temporizador deve estar em 30 segundos e deve continuar aumentando o aplicativo em segundo plano (com o botão inicial e a energia / tela desligada).
Como posso fazer isso? Eu tentei com serviço e manipulador, mas não está funcionando ...
EDITAR
Acompanhamento do meu serviço (processo com 30 s)
public class TrackingService extends IntentService {
private Handler mHandler;
private Runnable mRunnable;
public TrackingService() {
super("TrackingService");
}
public TrackingService(String name) {
super(name);
}
@Override
protected void onHandleIntent(Intent intent) {
long timer = 30000;
mHandler = new Handler();
mRunnable = new Runnable() {
@Override
public void run() {
//TODO - process with update timer for new 30 sec
mHandler.postDelayed(this, timer);
}
};
mHandler.postDelayed(mRunnable, timer);
}
}
Meu botão de clique:
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO - start first time and it continued every 30 seconds and continue in the background
startService(Intent intent = new Intent(this, TrackingService.class));
}
});