sqlite - Random behavior on button click at times in Android App -
not sure how should phrase it, in app single button click generates multiple events , hence ends sending multiple similar transactions server causing data integrity problem. here code flow, note code runs on users phone may have weaker connections @ times, hence store data in sqlite , there separate sync service sends data (fetching sqlite tables) server when internet connected.
this click captured , event posted main activity (landing page)
@onclick(r.id.btn_add_attempt) public void onattemptclick() { try{ btnaddattempt.setenabled(false); eventbus.getdefault().post(new exampleactionevent()); movetohomepage(); } catch (exception e){ e.printstacktrace(); crashlytics.logexception(e); } }
here event subscription main activity.
@subscribe() public void onexampleaction(exampleactionevent exampleactionevent) { if(application == null) application = (exapplication) getapplication(); final thread thread = new thread(new runnable() { @override public void run() { arraylist<something> somethings = application.getarray().getsomethings(); if (!exutils.validatesomethings(somethings)){ runonuithread(new runnable() { @override public void run() { riderutils.showsimplepopup( mainlandingactivity.this, getstring(r.string.title_alert), getstring(r.string.alert_message), getstring(r.string.done), null, false, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { showpendingsomething(); exutils.movetopending(mainlandingactivity.this); } }, null, false); } }); return; } status = application.getarray().getstatus(); imagelocalpath = application.getarray().getsomethings().get(0).getphotopath(); log.d(const.tag, "image path is: "+imagelocalpath); try { exutils.pushexampleactionevent(application.getarray(), mainlandingactivity.this, xyz, abc); } catch (exception e) { e.printstacktrace(); } filewriteevent filewriteevent = null; string currenttimestamp = application.getarray().gettimestamp(); switch (status) { case const.update_success: filewriteevent = new filewriteevent(const.event_csv_file_success_value, application.getarray(), "", cachedlocation, currenttimestamp, null); break; case const.update_attempted: filewriteevent = new filewriteevent(const.event_csv_file_attempted_value, riderapplication.getbulkarray(), "", cachedlocation, currenttimestamp, null); exutils.showsnackbar(holder, getstring(r.string.example), snackbar.length_long); break; } if(filewriteevent != null) { eventbus.getdefault().post(filewriteevent); } createall(); //sqlite db call inserting data runonuithread(new runnable() { @override public void run() { try { switch (status) { case const.update_success: riderutils.showsnackbar(holder, getstring(r.string.success), snackbar.length_long); break; case const.update_attempted: riderutils.showsnackbar(holder, getstring(r.string.failed), snackbar.length_long); break; } }catch (exception e) { e.printstacktrace(); } } }); } }); thread.start(); }
i not able figure out why misbehaving randomly otherwise runs smoothly, hence not able regenrate issue while debugging.
Comments
Post a Comment