android - Cancel/Modify Intent Message -


i want send confirmation second activity main activity. if checkbox marked want set intent data , set result returned activity true.

otherwise if checkbox unmarked want either:

  • modify intent set false
  • remove intent altogether if wasn't set

     confirmcheckbox.setonclicklistener(new view.onclicklistener() {   @override  public void onclick(view view) {          // view checked?         boolean checked = ((checkbox) view).ischecked();          if (checked) {             intent data = new intent();             data.putextra(extra_confirm, true);             setresult(result_ok, data);         }         else         {             // remove or modify false.         }     } }); 

how can either of actions modify or cancel intent message? also, know what's best way handle it?

you can use checkbox value value intent. there's no need have if/else construct.

@override public void onclick(view view) {      // view checked?     boolean checked = ((checkbox) view).ischecked();     intent data = new intent();     data.putextra(extra_confirm, true);     setresult(result_ok, data); } 

in mainactivity's onactivityresult can check intents extra_confirm , decide how react if value true/false.

thats basic approach handle data sending between activities. further reading: https://developer.android.com/training/basics/intents/result.html


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -