android - Starting countdown timer in background on receiving push notification -
android - Starting countdown timer in background on receiving push notification -
i want start countdown timer when force notification received.
i can receive notification successfully.
now want ask, possible start countdown timer in onreceive of broadcastreceiver when notification received , application in background or foreground?
simply, should timer should start whether app in foreground or not. , when timer finished should send info server. , need show remaining time in text view app comes foreground during countdown.
i adding code, please help me out.
this code start timer , function called in onreceive.
void startordercountdown() { countdowntimer ordercountdown = new countdowntimer(40000, 1000) { public void ontick(long millisuntilfinished) { constant.remainingtimeoforder = millisuntilfinished / 1000; log.v("timer", "time left: " + millisuntilfinished / 1000); } public void onfinish() { new thread(new runnable() { @override public void run() { string dr_id = mypreferences.getdriverid(); string res = new serverconnection() .updateordermissedrejected( constant.update_missed_rejected_order, dr_id, "", "0"); log.e("timer", "finished..." + res); } }).start(); } }; ordercountdown.start(); }
but when notification arrives, prints "time left: 39" in logcat.
thanks in advance.
no need countdown timer.
just follow steps.
1) create alarmmanagerbroadcastreceiver.java
public class alarmmanagerbroadcastreceiver extends broadcastreceiver implements ijoomersharedpreferences { @override public void onreceive(context context, intent intent) { // phone call sever task. } }
2) set alarm current time when receive force notification.
long interval = 40000; alarmmanager am=(alarmmanager)getsystemservice(context.alarm_service); intent intent = new intent(this, alarmmanagerbroadcastreceiver.class); pendingintent pi = pendingintent.getbroadcast(this, 1010, intent, 0); try{ am.cancel(pi); }catch (exception e){ } am.set(alarmmanager.rtc_wakeup, system.currenttimemillis() + interval, pi);
2) manifest.xml
<receiver android:process=":remote" android:name="com.xxx.zzzz.alarmmanagerbroadcastreceiver"></receiver>
android countdowntimer
Comments
Post a Comment