Radio Button bundle












0















I want to check that if my radio button is checked than on another activity it should use local ip and if my radio button is not checked then it should use ip provided by user i m doing it through bundle. I used following code but if condition is giving error Required boolean Found java.lang.String so how could i do this thing. I m beginner in Android Studio so don't know much.



Following is the code i used:



SelectRoomActivity



if(rb.isChecked()){
rb.setChecked(true);
SelectRoomActivity.bundle.putString("local","true");
}else{
rb.setChecked(false);
SelectRoomActivity.bundle.putString("local","false");
}


EntranceActivity



if (SelectRoomActivity.bundle.getString("false")){   //error is generated if condition
serverAdress = address; //abc.ddns.net
}
else{
serverAdress = lan; //192.168.1.101
}









share|improve this question

























  • You are passing String by the name local" and trying to get it in another activity by the name false. It will surely give an error.

    – nimi0112
    Nov 16 '18 at 10:23













  • If SelectRoomActivity.bundle is a static variable, that is a poor configuration for storing constants or configurations

    – cricket_007
    Nov 16 '18 at 10:25













  • Please read stackoverflow.com/questions/3624280/…

    – cricket_007
    Nov 16 '18 at 10:27











  • if you insist on using strings like this, at least change SelectRoomActivity.bundle.getString("false") to SelectRoomActivity.bundle.getString("local") to grab the right string

    – koksalb
    Nov 16 '18 at 10:28
















0















I want to check that if my radio button is checked than on another activity it should use local ip and if my radio button is not checked then it should use ip provided by user i m doing it through bundle. I used following code but if condition is giving error Required boolean Found java.lang.String so how could i do this thing. I m beginner in Android Studio so don't know much.



Following is the code i used:



SelectRoomActivity



if(rb.isChecked()){
rb.setChecked(true);
SelectRoomActivity.bundle.putString("local","true");
}else{
rb.setChecked(false);
SelectRoomActivity.bundle.putString("local","false");
}


EntranceActivity



if (SelectRoomActivity.bundle.getString("false")){   //error is generated if condition
serverAdress = address; //abc.ddns.net
}
else{
serverAdress = lan; //192.168.1.101
}









share|improve this question

























  • You are passing String by the name local" and trying to get it in another activity by the name false. It will surely give an error.

    – nimi0112
    Nov 16 '18 at 10:23













  • If SelectRoomActivity.bundle is a static variable, that is a poor configuration for storing constants or configurations

    – cricket_007
    Nov 16 '18 at 10:25













  • Please read stackoverflow.com/questions/3624280/…

    – cricket_007
    Nov 16 '18 at 10:27











  • if you insist on using strings like this, at least change SelectRoomActivity.bundle.getString("false") to SelectRoomActivity.bundle.getString("local") to grab the right string

    – koksalb
    Nov 16 '18 at 10:28














0












0








0








I want to check that if my radio button is checked than on another activity it should use local ip and if my radio button is not checked then it should use ip provided by user i m doing it through bundle. I used following code but if condition is giving error Required boolean Found java.lang.String so how could i do this thing. I m beginner in Android Studio so don't know much.



Following is the code i used:



SelectRoomActivity



if(rb.isChecked()){
rb.setChecked(true);
SelectRoomActivity.bundle.putString("local","true");
}else{
rb.setChecked(false);
SelectRoomActivity.bundle.putString("local","false");
}


EntranceActivity



if (SelectRoomActivity.bundle.getString("false")){   //error is generated if condition
serverAdress = address; //abc.ddns.net
}
else{
serverAdress = lan; //192.168.1.101
}









share|improve this question
















I want to check that if my radio button is checked than on another activity it should use local ip and if my radio button is not checked then it should use ip provided by user i m doing it through bundle. I used following code but if condition is giving error Required boolean Found java.lang.String so how could i do this thing. I m beginner in Android Studio so don't know much.



Following is the code i used:



SelectRoomActivity



if(rb.isChecked()){
rb.setChecked(true);
SelectRoomActivity.bundle.putString("local","true");
}else{
rb.setChecked(false);
SelectRoomActivity.bundle.putString("local","false");
}


EntranceActivity



if (SelectRoomActivity.bundle.getString("false")){   //error is generated if condition
serverAdress = address; //abc.ddns.net
}
else{
serverAdress = lan; //192.168.1.101
}






java android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 12:22









Fantômas

32.8k156491




32.8k156491










asked Nov 16 '18 at 10:17









Ahmed AnsariAhmed Ansari

97




97













  • You are passing String by the name local" and trying to get it in another activity by the name false. It will surely give an error.

    – nimi0112
    Nov 16 '18 at 10:23













  • If SelectRoomActivity.bundle is a static variable, that is a poor configuration for storing constants or configurations

    – cricket_007
    Nov 16 '18 at 10:25













  • Please read stackoverflow.com/questions/3624280/…

    – cricket_007
    Nov 16 '18 at 10:27











  • if you insist on using strings like this, at least change SelectRoomActivity.bundle.getString("false") to SelectRoomActivity.bundle.getString("local") to grab the right string

    – koksalb
    Nov 16 '18 at 10:28



















  • You are passing String by the name local" and trying to get it in another activity by the name false. It will surely give an error.

    – nimi0112
    Nov 16 '18 at 10:23













  • If SelectRoomActivity.bundle is a static variable, that is a poor configuration for storing constants or configurations

    – cricket_007
    Nov 16 '18 at 10:25













  • Please read stackoverflow.com/questions/3624280/…

    – cricket_007
    Nov 16 '18 at 10:27











  • if you insist on using strings like this, at least change SelectRoomActivity.bundle.getString("false") to SelectRoomActivity.bundle.getString("local") to grab the right string

    – koksalb
    Nov 16 '18 at 10:28

















You are passing String by the name local" and trying to get it in another activity by the name false. It will surely give an error.

– nimi0112
Nov 16 '18 at 10:23







You are passing String by the name local" and trying to get it in another activity by the name false. It will surely give an error.

– nimi0112
Nov 16 '18 at 10:23















If SelectRoomActivity.bundle is a static variable, that is a poor configuration for storing constants or configurations

– cricket_007
Nov 16 '18 at 10:25







If SelectRoomActivity.bundle is a static variable, that is a poor configuration for storing constants or configurations

– cricket_007
Nov 16 '18 at 10:25















Please read stackoverflow.com/questions/3624280/…

– cricket_007
Nov 16 '18 at 10:27





Please read stackoverflow.com/questions/3624280/…

– cricket_007
Nov 16 '18 at 10:27













if you insist on using strings like this, at least change SelectRoomActivity.bundle.getString("false") to SelectRoomActivity.bundle.getString("local") to grab the right string

– koksalb
Nov 16 '18 at 10:28





if you insist on using strings like this, at least change SelectRoomActivity.bundle.getString("false") to SelectRoomActivity.bundle.getString("local") to grab the right string

– koksalb
Nov 16 '18 at 10:28












3 Answers
3






active

oldest

votes


















3














Try that
In you'r code you'r put String into your bundle, you need to put boolean
When you get your variable in Entrance Activity, the string used are the name of you'r Boolean in the bundle ("local", and no "false")



SelectRoomActivity



if(rb.isChecked()){
rb.setChecked(true);
SelectRoomActivity.bundle.putBoolean("local",true);
}
else{
rb.setChecked(false);
SelectRoomActivity.bundle.putBoolean("local",false);
}


EntranceActivity



if (SelectRoomActivity.bundle.getBoolean("local")){   //error is generated if condition
serverAdress = address; //abc.ddns.net
}
else{
serverAdress = lan; //192.168.1.101
}





share|improve this answer
























  • this is a better approach.

    – Karan Mer
    Nov 16 '18 at 10:31



















1














Change this



SelectRoomActivity.bundle.putString("local","true"); AND

SelectRoomActivity.bundle.putString("local","false");


TO



SelectRoomActivity.bundle.putBoolean("local",true); AND 

SelectRoomActivity.bundle.putBoolean("local",false);


And on NExt Activity



if (SelectRoomActivity.bundle.getBoolean("local")){  
serverAdress = address; //abc.ddns.net
}
else{
serverAdress = lan; //192.168.1.101
}





share|improve this answer





















  • 2





    Maybe to add a check if bundles are null might be a good practice.

    – nimi0112
    Nov 16 '18 at 10:25





















0














SelectRoomActivity



if(rb.isChecked()){
rb.setChecked(true);
SelectRoomActivity.bundle.putString("local","true");
}else{
rb.setChecked(false);
SelectRoomActivity.bundle.putString("local","false");
}


and in EntranceActivity



if (SelectRoomActivity.bundle.getString("local").equalsIgnoreCase("false")){   
//error is generated if condition
serverAdress = address; //abc.ddns.net
}
else{
serverAdress = lan; //192.168.1.101
}





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335749%2fradio-button-bundle%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Try that
    In you'r code you'r put String into your bundle, you need to put boolean
    When you get your variable in Entrance Activity, the string used are the name of you'r Boolean in the bundle ("local", and no "false")



    SelectRoomActivity



    if(rb.isChecked()){
    rb.setChecked(true);
    SelectRoomActivity.bundle.putBoolean("local",true);
    }
    else{
    rb.setChecked(false);
    SelectRoomActivity.bundle.putBoolean("local",false);
    }


    EntranceActivity



    if (SelectRoomActivity.bundle.getBoolean("local")){   //error is generated if condition
    serverAdress = address; //abc.ddns.net
    }
    else{
    serverAdress = lan; //192.168.1.101
    }





    share|improve this answer
























    • this is a better approach.

      – Karan Mer
      Nov 16 '18 at 10:31
















    3














    Try that
    In you'r code you'r put String into your bundle, you need to put boolean
    When you get your variable in Entrance Activity, the string used are the name of you'r Boolean in the bundle ("local", and no "false")



    SelectRoomActivity



    if(rb.isChecked()){
    rb.setChecked(true);
    SelectRoomActivity.bundle.putBoolean("local",true);
    }
    else{
    rb.setChecked(false);
    SelectRoomActivity.bundle.putBoolean("local",false);
    }


    EntranceActivity



    if (SelectRoomActivity.bundle.getBoolean("local")){   //error is generated if condition
    serverAdress = address; //abc.ddns.net
    }
    else{
    serverAdress = lan; //192.168.1.101
    }





    share|improve this answer
























    • this is a better approach.

      – Karan Mer
      Nov 16 '18 at 10:31














    3












    3








    3







    Try that
    In you'r code you'r put String into your bundle, you need to put boolean
    When you get your variable in Entrance Activity, the string used are the name of you'r Boolean in the bundle ("local", and no "false")



    SelectRoomActivity



    if(rb.isChecked()){
    rb.setChecked(true);
    SelectRoomActivity.bundle.putBoolean("local",true);
    }
    else{
    rb.setChecked(false);
    SelectRoomActivity.bundle.putBoolean("local",false);
    }


    EntranceActivity



    if (SelectRoomActivity.bundle.getBoolean("local")){   //error is generated if condition
    serverAdress = address; //abc.ddns.net
    }
    else{
    serverAdress = lan; //192.168.1.101
    }





    share|improve this answer













    Try that
    In you'r code you'r put String into your bundle, you need to put boolean
    When you get your variable in Entrance Activity, the string used are the name of you'r Boolean in the bundle ("local", and no "false")



    SelectRoomActivity



    if(rb.isChecked()){
    rb.setChecked(true);
    SelectRoomActivity.bundle.putBoolean("local",true);
    }
    else{
    rb.setChecked(false);
    SelectRoomActivity.bundle.putBoolean("local",false);
    }


    EntranceActivity



    if (SelectRoomActivity.bundle.getBoolean("local")){   //error is generated if condition
    serverAdress = address; //abc.ddns.net
    }
    else{
    serverAdress = lan; //192.168.1.101
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 16 '18 at 10:24









    BenjaminBenjamin

    929




    929













    • this is a better approach.

      – Karan Mer
      Nov 16 '18 at 10:31



















    • this is a better approach.

      – Karan Mer
      Nov 16 '18 at 10:31

















    this is a better approach.

    – Karan Mer
    Nov 16 '18 at 10:31





    this is a better approach.

    – Karan Mer
    Nov 16 '18 at 10:31













    1














    Change this



    SelectRoomActivity.bundle.putString("local","true"); AND

    SelectRoomActivity.bundle.putString("local","false");


    TO



    SelectRoomActivity.bundle.putBoolean("local",true); AND 

    SelectRoomActivity.bundle.putBoolean("local",false);


    And on NExt Activity



    if (SelectRoomActivity.bundle.getBoolean("local")){  
    serverAdress = address; //abc.ddns.net
    }
    else{
    serverAdress = lan; //192.168.1.101
    }





    share|improve this answer





















    • 2





      Maybe to add a check if bundles are null might be a good practice.

      – nimi0112
      Nov 16 '18 at 10:25


















    1














    Change this



    SelectRoomActivity.bundle.putString("local","true"); AND

    SelectRoomActivity.bundle.putString("local","false");


    TO



    SelectRoomActivity.bundle.putBoolean("local",true); AND 

    SelectRoomActivity.bundle.putBoolean("local",false);


    And on NExt Activity



    if (SelectRoomActivity.bundle.getBoolean("local")){  
    serverAdress = address; //abc.ddns.net
    }
    else{
    serverAdress = lan; //192.168.1.101
    }





    share|improve this answer





















    • 2





      Maybe to add a check if bundles are null might be a good practice.

      – nimi0112
      Nov 16 '18 at 10:25
















    1












    1








    1







    Change this



    SelectRoomActivity.bundle.putString("local","true"); AND

    SelectRoomActivity.bundle.putString("local","false");


    TO



    SelectRoomActivity.bundle.putBoolean("local",true); AND 

    SelectRoomActivity.bundle.putBoolean("local",false);


    And on NExt Activity



    if (SelectRoomActivity.bundle.getBoolean("local")){  
    serverAdress = address; //abc.ddns.net
    }
    else{
    serverAdress = lan; //192.168.1.101
    }





    share|improve this answer















    Change this



    SelectRoomActivity.bundle.putString("local","true"); AND

    SelectRoomActivity.bundle.putString("local","false");


    TO



    SelectRoomActivity.bundle.putBoolean("local",true); AND 

    SelectRoomActivity.bundle.putBoolean("local",false);


    And on NExt Activity



    if (SelectRoomActivity.bundle.getBoolean("local")){  
    serverAdress = address; //abc.ddns.net
    }
    else{
    serverAdress = lan; //192.168.1.101
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 16 '18 at 10:27

























    answered Nov 16 '18 at 10:20









    Ali AhmedAli Ahmed

    1,3891314




    1,3891314








    • 2





      Maybe to add a check if bundles are null might be a good practice.

      – nimi0112
      Nov 16 '18 at 10:25
















    • 2





      Maybe to add a check if bundles are null might be a good practice.

      – nimi0112
      Nov 16 '18 at 10:25










    2




    2





    Maybe to add a check if bundles are null might be a good practice.

    – nimi0112
    Nov 16 '18 at 10:25







    Maybe to add a check if bundles are null might be a good practice.

    – nimi0112
    Nov 16 '18 at 10:25













    0














    SelectRoomActivity



    if(rb.isChecked()){
    rb.setChecked(true);
    SelectRoomActivity.bundle.putString("local","true");
    }else{
    rb.setChecked(false);
    SelectRoomActivity.bundle.putString("local","false");
    }


    and in EntranceActivity



    if (SelectRoomActivity.bundle.getString("local").equalsIgnoreCase("false")){   
    //error is generated if condition
    serverAdress = address; //abc.ddns.net
    }
    else{
    serverAdress = lan; //192.168.1.101
    }





    share|improve this answer




























      0














      SelectRoomActivity



      if(rb.isChecked()){
      rb.setChecked(true);
      SelectRoomActivity.bundle.putString("local","true");
      }else{
      rb.setChecked(false);
      SelectRoomActivity.bundle.putString("local","false");
      }


      and in EntranceActivity



      if (SelectRoomActivity.bundle.getString("local").equalsIgnoreCase("false")){   
      //error is generated if condition
      serverAdress = address; //abc.ddns.net
      }
      else{
      serverAdress = lan; //192.168.1.101
      }





      share|improve this answer


























        0












        0








        0







        SelectRoomActivity



        if(rb.isChecked()){
        rb.setChecked(true);
        SelectRoomActivity.bundle.putString("local","true");
        }else{
        rb.setChecked(false);
        SelectRoomActivity.bundle.putString("local","false");
        }


        and in EntranceActivity



        if (SelectRoomActivity.bundle.getString("local").equalsIgnoreCase("false")){   
        //error is generated if condition
        serverAdress = address; //abc.ddns.net
        }
        else{
        serverAdress = lan; //192.168.1.101
        }





        share|improve this answer













        SelectRoomActivity



        if(rb.isChecked()){
        rb.setChecked(true);
        SelectRoomActivity.bundle.putString("local","true");
        }else{
        rb.setChecked(false);
        SelectRoomActivity.bundle.putString("local","false");
        }


        and in EntranceActivity



        if (SelectRoomActivity.bundle.getString("local").equalsIgnoreCase("false")){   
        //error is generated if condition
        serverAdress = address; //abc.ddns.net
        }
        else{
        serverAdress = lan; //192.168.1.101
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 10:35









        BasiBasi

        631516




        631516






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335749%2fradio-button-bundle%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python