Eu tive que realizar o mesmo procedimento, não sei se a solução apresentada sera a melhor solução, porem para minha necessidade funcionou perfeitamente...
Sendo assim utilizei um Servive, e o chamei na primeira tela de minha aplicação no onCreate da seguinte forma:
Intent it = new Intent(context, ServiceTeste .class);
context.startService(it);
Apos utilizei um Time no Service para executar em certo determinado tempo:Sendo assim utilizei um Servive, e o chamei na primeira tela de minha aplicação no onCreate da seguinte forma:
Intent it = new Intent(context, ServiceTeste .class);
context.startService(it);
public class ServiceTeste extends Service{
private static final String TAG = "ServiceTeste ";
private Timer timer=new Timer();
private static long UPDATE_INTERVAL = 1*60*1000; //1 minuto
private static long DELAY_INTERVAL = 0;
@Override
public void onCreate()
{
super.onCreate();
try{
startService();
}
catch (Exception e) {
// TODO: handle exception
Log.d(TAG,"onCreate():"+e.getMessage());
}
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onDestroy()
{
super.onDestroy();
Log.d(TAG,"onDestroy");
stopService();
}
private void startService() throws Exception
{
timer.scheduleAtFixedRate(
new TimerTask() {
public void run() {
try {
doServiceWork();
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d(TAG,"scheduleAtFixedRate():"+e.getMessage());
}
}
},
DELAY_INTERVAL,
UPDATE_INTERVAL);
}
private void stopService()
{
//timer.cancel();
}
Em 2 de abril de 2013 09:06, Rogerio Esteves <rolives@gmail.com> escreveu:
Eu implementei com um BroadcastReceiver com action android.intent.action.BOOT_COMPLETED,No meu BroadcastReceiver eu implementei um AlarmManager para chamar meu serviço em um tempo determinado, porém ele esta chamando somente um vez o meu serviço. Tentei com IntentService e ficou em loop como eu queria porém como preciso enviar um Notification então IntentService não posso usar.--
Em 2 de abril de 2013 08:43, Rodrigo Medeiros <rodriigomedeiros@gmail.com> escreveu:Procure por Google Cloud Messaging, talvez te ajude, Rogério.Em 2 de abril de 2013 08:40, Felipe Costa <felipetce@gmail.com> escreveu:
De uma olhada em Service e Thread ou Timer!
Em segunda-feira, 1 de abril de 2013 19h29min56s UTC-3, Rogerio Esteves escreveu:Qual seria a melhor forma de criar um serviço em segundo plano sendo que preciso este serviço rode em um tempo estimado e também preciso que seja dada uma notificação dependendo de uma regra especifica retornada de um web service. Este serviço deverá chamar um web service.--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--Rodrigo Azevedo de MedeirosMestrando em Ciência da Computação (PPgCC UERN/UFERSA)Bacharel em Ciência da Computação (UERN)--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to a topic in the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/androidbrasil-dev/Wy63CF-mYNA/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
Att,
Felipe Costa
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.






0 comentários:
Postar um comentário