android - Progress bar - generate wrong time -
i have problem when adding card app , when card set go details. there time new card generated. works fine generate new card , go detail, time generate new card not since then, fixed moment. example, time generate new card 30 , starts @ 15. looks takes on time of first card. not know why happening.
public class carddetailsactivity extends appcompatactivity {
mysharepreference mysharepreference; private string intervaltotpencrypt; private progressbar progressbar; private textview secondtimetextview; private int interval; protected string intervaltotpdecrypt; private imageview myimageview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_card_details); textview titletextview = (textview) findviewbyid(r.id.toolbar_title); titletextview.settext(cardnamedecrypt); textview dottextview = (textview) findviewbyid(r.id.dottextview); subtitletextview.settypeface(custom_fonts); second_text.settypeface(custom_fonts); setsupportactionbar(toolbar); progressbar = (progressbar) findviewbyid(r.id.refershprogrss); myimageview = (imageview) findviewbyid(r.id.qrcodeimageview); mysharepreference = new mysharepreference(); bundle extras = getintent().getextras(); intervaltotpencrypt = extras.getstring("intervaltotp"); keystring = mysharepreference.getkeystring(carddetailsactivity.this); typeface custom_fonts = typeface.createfromasset(getassets(), "fonts/opensans-regular.ttf"); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); toolbar.setnavigationicon(r.drawable.ic_arrow_back); try { intervaltotpdecrypt = aescrypt.decrypt(keystring, intervaltotpencrypt); } catch (generalsecurityexception e) { e.printstacktrace(); } interval = integer.parseint(intervaltotpdecrypt); localbroadcastmanager.getinstance(this).registerreceiver(mmessagereceiver, new intentfilter(progressbarservice.download_action)); intent intent = new intent(this, progressbarservice.class); intent.putextra("interval", interval); startservice(intent); progressbar.setmax(interval); progressbar.setprogress(interval); } @override protected void ondestroy() { super.ondestroy(); localbroadcastmanager.getinstance(this).unregisterreceiver(mmessagereceiver); } private broadcastreceiver mmessagereceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { if (intent != null) { int progress = intent.getintextra(progressbarservice.percentage_stamp, 0); progressbar.setprogress(progress); secondtimetextview.settext(" " + progress + " "); } } };
}
my progressservice.class
public class progressbarservice extends service { private int interval; private intent intent; private localbroadcastmanager broadcastmanager; public final static string percentage_stamp = "percent"; public final static string download_action = "com.magdad.apk.download"; public progressbarservice() { } @override public void oncreate() { super.oncreate(); broadcastmanager = localbroadcastmanager.getinstance(this); } @override public int onstartcommand(intent intent, int flags, int startid) { if (intent != null) { interval = intent.getintextra("interval", 0); } new updateprogressbar().execute(); return start_sticky; } @override public ibinder onbind(intent intent) { // todo: return communication channel service. throw new unsupportedoperationexception("not yet implemented"); } private class updateprogressbar extends asynctask<void, integer, integer> { @override protected void onprogressupdate(integer... values) { super.onprogressupdate(values); intent = new intent(download_action); intent.putextra(percentage_stamp, values[0]); broadcastmanager.sendbroadcast(intent); } @override protected integer doinbackground(void... params) { (int = interval; >= 0; i--) { publishprogress(i); try { thread.sleep(1000); } catch (interruptedexception e) { e.printstacktrace(); } } return null; } @override protected void onpostexecute(integer integer) { super.onpostexecute(integer); new updateprogressbar().execute(); } }
Comments
Post a Comment