How can I every 1 second command intentfilter on android? -


i want every 1 second registerreceiver.

i try

registerreceiver(receiver, new intentfilter(intent.action_time_tick)); 

but code every 1 minute

i want every 1 second.

perhaps, android have form ?

thanks

what trying accomplish? if want have code executed every 1s, don't user broadcastreceiver. receivers result in inter-process communication every time triggered (relatively) expensive.

best way use handler,

private static final long tick_interval = timeunit.seconds.tomillis(1); private static final handler tickhandler = new handler(looper.getmainlooper());  public void onresume() {   super.onresume();   tick(tick_interval); }  private void tick(final long interval) {   tickhandler.postdelayed(     new runnable() {       public void run() {         tick(interval);         ontick();       }     },   ); }  protected void ontick() {   // } 

ensure stop ticking when activity pauses,

public void onpause() {   super.onpause();   tickhandler.removecallbacksandmessages(null); } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -