android - Stop execution until User selects a button from the Alert Dialog -



android - Stop execution until User selects a button from the Alert Dialog -

in android application utilize conflicthandler class inorder observe conflicts between records of mobile device's db , server's db. when conflict detected,i want display alert dialog user can take record version "win"(server's or mobile device's). have set code of alert dialog in class of conflicthandler, when conflict detected alert dialog pops up. problem code execution doesn't stop when alert dialog pops up, user can select action done. returns serveritem.

private class conflictresolvingsynchandler implements mobileservicesynchandler { @override public jsonobject executetableoperation( final remotetableoperationprocessor processor, final tableoperation operation) throws mobileservicesynchandlerexception { final jsonobject clientitem = processor.getitem().getasjsonobject(); mobileservicepreconditionfailedexceptionbase ex = null; final jsonobject[] result = {null}; seek { result[0] = operation.accept(processor); } grab (mobileservicepreconditionfailedexceptionbase e) { ex = e; } grab (throwable e) { ex = (mobileservicepreconditionfailedexceptionbase) e.getcause(); } if (ex != null) { // conflict detected; let's forcefulness server "win" // discarding client version of item final alertdialog.builder alertdialogbuilder = new alertdialog.builder( context); // set title alertdialogbuilder.settitle("conflict detected"); // set dialog message final mobileservicepreconditionfailedexceptionbase finalex = ex; alertdialogbuilder .setmessage("choose winner") .setcancelable(false) .setpositivebutton("server",new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog,int id) { // if button clicked, server wins jsonobject serveritem = finalex.getvalue(); if (serveritem == null) { // item not returned in exception, retrieving server seek { serveritem = mclient.gettable(operation.gettablename()).lookup(operation.getitemid()).get(); } grab (exception e) { seek { throw new mobileservicesynchandlerexception(e); } grab (mobileservicesynchandlerexception e1) { e1.printstacktrace(); } } } result[0] = serveritem; } }) .setnegativebutton("client",new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog,int id) { // if button clicked, client wins result[0]=clientitem; } }); runonuithread(new runnable() { @override public void run() { // create alert dialog alertdialog alertdialog = alertdialogbuilder.create(); // show alertdialog.show(); } }); } homecoming result[0]; } @override public void onpushcomplete(mobileservicepushcompletionresult result) throws mobileservicesynchandlerexception { } }

you need block thread executing executetableoperation until user clicks in dialog. example, using countdownlatch, in code below:

private class conflictresolvingsynchandler implements mobileservicesynchandler { @override public jsonobject executetableoperation( final remotetableoperationprocessor processor, final tableoperation operation) throws mobileservicesynchandlerexception { final jsonobject clientitem = processor.getitem().getasjsonobject(); mobileservicepreconditionfailedexceptionbase ex = null; final jsonobject[] result = {null}; seek { result[0] = operation.accept(processor); } grab (mobileservicepreconditionfailedexceptionbase e) { ex = e; } grab (throwable e) { ex = (mobileservicepreconditionfailedexceptionbase) e.getcause(); } if (ex != null) { // conflict detected; let's create client take "wins" final alertdialog.builder alertdialogbuilder = new alertdialog.builder( context); final countdownlatch latch = new countdownlatch(1); // set title alertdialogbuilder.settitle("conflict detected"); // set dialog message final mobileservicepreconditionfailedexceptionbase finalex = ex; alertdialogbuilder .setmessage("choose winner") .setcancelable(false) .setpositivebutton("server",new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog,int id) { // if button clicked, server wins jsonobject serveritem = finalex.getvalue(); if (serveritem == null) { // item not returned in exception, retrieving server seek { serveritem = mclient.gettable(operation.gettablename()).lookup(operation.getitemid()).get(); } grab (exception e) { seek { throw new mobileservicesynchandlerexception(e); } grab (mobileservicesynchandlerexception e1) { e1.printstacktrace(); } } } result[0] = serveritem; latch.countdown(); } }) .setnegativebutton("client",new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog,int id) { // if button clicked, client wins result[0] = clientitem; latch.countdown(); } }); runonuithread(new runnable() { @override public void run() { // create alert dialog alertdialog alertdialog = alertdialogbuilder.create(); // show alertdialog.show(); } }); seek { latch.await(); } grab (interruptedexception e) { e.printstacktrace(); } } homecoming result[0]; } @override public void onpushcomplete(mobileservicepushcompletionresult result) throws mobileservicesynchandlerexception { } }

android conflict azure-mobile-services

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -