android - OnActivityResult for 2 different activites -


i trying initialize/ turn on nfc , bt modules in same activity. need them both enabled before continue task.

i understand onresultactivity async trying figure out best way achieve it?

here's of code:

protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         initbt();         initnfc();          intent nextintent;               if(savesharedpreference.getusername(mainactivity.this).length() == 0)         {             nextintent = new intent(mainactivity.this, loginactivity.class);         }         else         {             nextintent = new intent(mainactivity.this, mainmenuactivity.class);         }            startactivity(nextintent);         finish();     }       private void initbt() {         if(btmodule.getinstance().initbt().equals(constants.ebluetoothstatus.bt_disabled)){             intent enablebtintent = new intent(btmodule.getadapter().action_request_enable);             startactivityforresult(enablebtintent, request_enable_bt);         }     }      private void initnfc(){          mnfcstate = nfcmodule.initnfc(this);         if(mnfcstate == enfcstatus.nfc_not_supported){             toast.maketext(this, "nfc not suppoeted device", toast.length_long).show();         }         else if(mnfcstate == enfcstatus.nfc_disabled){             intent nfcintent;             if(android.os.build.version.sdk_int >= 16){                 nfcintent = new intent(android.provider.settings.action_nfc_settings);               }             else{             nfcintent = new intent(android.provider.settings.action_wireless_settings);             }             startactivity(nfcintent);             toast.maketext(this, "please enable nfc", toast.length_long);         }         else{             toast.maketext(this, "nfc , running", toast.length_long).show();         }     }      @override     protected void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);         if(resultcode == ebluetoothstatus.bt_ok.ordinal()){             toast.maketext(this, "bt , running", toast.length_long).show();             return;         }      }  } 

as newbie please feel free correct me if wrong :)

thanks!!

use startactivityforresult instead of startactivity in initnfc method. define 2 boolean variables isnfcenabled , isbtenabled. in onactivityresult method check booleans. if both of them enable, whatever want.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -