How to open Mainactivity after login success with PHP massage?












-1















I am trying to open Mainactivity after login success



protected void onPostExecute(JSONObject result) {
try {
if (result != null) {
Toast.makeText(getApplicationContext(),result.getString("message"),Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}


"message" from PHP: "Successfully logged in" and "Incorrect details"



If i change:



protected void onPostExecute(JSONObject result) {
try {
if (result != null) {
Toast.makeText(getApplicationContext(), result.getString("message"), Toast.LENGTH_LONG).show();
Intent i = new Intent(getApplicationContext(), MainActivity.class);
getApplicationContext().startActivity(i);
} else {
Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}


When both logged in successfully or failed, it enter MainActivity
Somebody help me










share|improve this question

























  • Check out this project on github. It also uses login and signup in both the apps.

    – Sayok Majumder
    Nov 16 '18 at 7:51
















-1















I am trying to open Mainactivity after login success



protected void onPostExecute(JSONObject result) {
try {
if (result != null) {
Toast.makeText(getApplicationContext(),result.getString("message"),Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}


"message" from PHP: "Successfully logged in" and "Incorrect details"



If i change:



protected void onPostExecute(JSONObject result) {
try {
if (result != null) {
Toast.makeText(getApplicationContext(), result.getString("message"), Toast.LENGTH_LONG).show();
Intent i = new Intent(getApplicationContext(), MainActivity.class);
getApplicationContext().startActivity(i);
} else {
Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}


When both logged in successfully or failed, it enter MainActivity
Somebody help me










share|improve this question

























  • Check out this project on github. It also uses login and signup in both the apps.

    – Sayok Majumder
    Nov 16 '18 at 7:51














-1












-1








-1








I am trying to open Mainactivity after login success



protected void onPostExecute(JSONObject result) {
try {
if (result != null) {
Toast.makeText(getApplicationContext(),result.getString("message"),Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}


"message" from PHP: "Successfully logged in" and "Incorrect details"



If i change:



protected void onPostExecute(JSONObject result) {
try {
if (result != null) {
Toast.makeText(getApplicationContext(), result.getString("message"), Toast.LENGTH_LONG).show();
Intent i = new Intent(getApplicationContext(), MainActivity.class);
getApplicationContext().startActivity(i);
} else {
Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}


When both logged in successfully or failed, it enter MainActivity
Somebody help me










share|improve this question
















I am trying to open Mainactivity after login success



protected void onPostExecute(JSONObject result) {
try {
if (result != null) {
Toast.makeText(getApplicationContext(),result.getString("message"),Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}


"message" from PHP: "Successfully logged in" and "Incorrect details"



If i change:



protected void onPostExecute(JSONObject result) {
try {
if (result != null) {
Toast.makeText(getApplicationContext(), result.getString("message"), Toast.LENGTH_LONG).show();
Intent i = new Intent(getApplicationContext(), MainActivity.class);
getApplicationContext().startActivity(i);
} else {
Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}


When both logged in successfully or failed, it enter MainActivity
Somebody help me







php android login






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 7:13









Rohit5k2

14.6k42752




14.6k42752










asked Nov 16 '18 at 6:55









Bon BonBon Bon

91




91













  • Check out this project on github. It also uses login and signup in both the apps.

    – Sayok Majumder
    Nov 16 '18 at 7:51



















  • Check out this project on github. It also uses login and signup in both the apps.

    – Sayok Majumder
    Nov 16 '18 at 7:51

















Check out this project on github. It also uses login and signup in both the apps.

– Sayok Majumder
Nov 16 '18 at 7:51





Check out this project on github. It also uses login and signup in both the apps.

– Sayok Majumder
Nov 16 '18 at 7:51












4 Answers
4






active

oldest

votes


















0














Replace your if condition with below condition.



  if (result != null && result.getString("message").contains("Successfully logged in"))





share|improve this answer































    0














    Based on your code, you will enter MainActivity when the result object is not null. You should add more conditions for entering MainActivity, like:



    if (result != null && result.getString("result").equals("success"))





    share|improve this answer


























    • Sorry mate, by mistake I modified your answer instead of me. Reverting.

      – Rohit5k2
      Nov 16 '18 at 7:09



















    0














    You are just checking if result is null or not. You should check for the exact status of login by modifying your code something like this.



    if (result != null && result.optString("message", "failed").equals("Successfully logged in"))


    Using optString will do good even if the value for "message" is null.



    NOTE: You can modify the code based on your JSON structure.






    share|improve this answer

































      -1














      protected void onPostExecute(JSONObject result) {
      try {
      if (result.length() != 0) {
      Toast.makeText(getApplicationContext(), result.getString("message"), Toast.LENGTH_LONG).show();
      Intent i = new Intent(getApplicationContext(), MainActivity.class);
      startActivity(i);

      } else {
      Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
      }
      } catch (JSONException e) {
      e.printStackTrace();
      }
      }





      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%2f53332857%2fhow-to-open-mainactivity-after-login-success-with-php-massage%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        Replace your if condition with below condition.



          if (result != null && result.getString("message").contains("Successfully logged in"))





        share|improve this answer




























          0














          Replace your if condition with below condition.



            if (result != null && result.getString("message").contains("Successfully logged in"))





          share|improve this answer


























            0












            0








            0







            Replace your if condition with below condition.



              if (result != null && result.getString("message").contains("Successfully logged in"))





            share|improve this answer













            Replace your if condition with below condition.



              if (result != null && result.getString("message").contains("Successfully logged in"))






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 16 '18 at 7:04









            JoyJoy

            315




            315

























                0














                Based on your code, you will enter MainActivity when the result object is not null. You should add more conditions for entering MainActivity, like:



                if (result != null && result.getString("result").equals("success"))





                share|improve this answer


























                • Sorry mate, by mistake I modified your answer instead of me. Reverting.

                  – Rohit5k2
                  Nov 16 '18 at 7:09
















                0














                Based on your code, you will enter MainActivity when the result object is not null. You should add more conditions for entering MainActivity, like:



                if (result != null && result.getString("result").equals("success"))





                share|improve this answer


























                • Sorry mate, by mistake I modified your answer instead of me. Reverting.

                  – Rohit5k2
                  Nov 16 '18 at 7:09














                0












                0








                0







                Based on your code, you will enter MainActivity when the result object is not null. You should add more conditions for entering MainActivity, like:



                if (result != null && result.getString("result").equals("success"))





                share|improve this answer















                Based on your code, you will enter MainActivity when the result object is not null. You should add more conditions for entering MainActivity, like:



                if (result != null && result.getString("result").equals("success"))






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 16 '18 at 7:05









                Rohit5k2

                14.6k42752




                14.6k42752










                answered Nov 16 '18 at 7:02









                mikemike

                19111




                19111













                • Sorry mate, by mistake I modified your answer instead of me. Reverting.

                  – Rohit5k2
                  Nov 16 '18 at 7:09



















                • Sorry mate, by mistake I modified your answer instead of me. Reverting.

                  – Rohit5k2
                  Nov 16 '18 at 7:09

















                Sorry mate, by mistake I modified your answer instead of me. Reverting.

                – Rohit5k2
                Nov 16 '18 at 7:09





                Sorry mate, by mistake I modified your answer instead of me. Reverting.

                – Rohit5k2
                Nov 16 '18 at 7:09











                0














                You are just checking if result is null or not. You should check for the exact status of login by modifying your code something like this.



                if (result != null && result.optString("message", "failed").equals("Successfully logged in"))


                Using optString will do good even if the value for "message" is null.



                NOTE: You can modify the code based on your JSON structure.






                share|improve this answer






























                  0














                  You are just checking if result is null or not. You should check for the exact status of login by modifying your code something like this.



                  if (result != null && result.optString("message", "failed").equals("Successfully logged in"))


                  Using optString will do good even if the value for "message" is null.



                  NOTE: You can modify the code based on your JSON structure.






                  share|improve this answer




























                    0












                    0








                    0







                    You are just checking if result is null or not. You should check for the exact status of login by modifying your code something like this.



                    if (result != null && result.optString("message", "failed").equals("Successfully logged in"))


                    Using optString will do good even if the value for "message" is null.



                    NOTE: You can modify the code based on your JSON structure.






                    share|improve this answer















                    You are just checking if result is null or not. You should check for the exact status of login by modifying your code something like this.



                    if (result != null && result.optString("message", "failed").equals("Successfully logged in"))


                    Using optString will do good even if the value for "message" is null.



                    NOTE: You can modify the code based on your JSON structure.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 16 '18 at 7:14

























                    answered Nov 16 '18 at 7:04









                    Rohit5k2Rohit5k2

                    14.6k42752




                    14.6k42752























                        -1














                        protected void onPostExecute(JSONObject result) {
                        try {
                        if (result.length() != 0) {
                        Toast.makeText(getApplicationContext(), result.getString("message"), Toast.LENGTH_LONG).show();
                        Intent i = new Intent(getApplicationContext(), MainActivity.class);
                        startActivity(i);

                        } else {
                        Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
                        }
                        } catch (JSONException e) {
                        e.printStackTrace();
                        }
                        }





                        share|improve this answer




























                          -1














                          protected void onPostExecute(JSONObject result) {
                          try {
                          if (result.length() != 0) {
                          Toast.makeText(getApplicationContext(), result.getString("message"), Toast.LENGTH_LONG).show();
                          Intent i = new Intent(getApplicationContext(), MainActivity.class);
                          startActivity(i);

                          } else {
                          Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
                          }
                          } catch (JSONException e) {
                          e.printStackTrace();
                          }
                          }





                          share|improve this answer


























                            -1












                            -1








                            -1







                            protected void onPostExecute(JSONObject result) {
                            try {
                            if (result.length() != 0) {
                            Toast.makeText(getApplicationContext(), result.getString("message"), Toast.LENGTH_LONG).show();
                            Intent i = new Intent(getApplicationContext(), MainActivity.class);
                            startActivity(i);

                            } else {
                            Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
                            }
                            } catch (JSONException e) {
                            e.printStackTrace();
                            }
                            }





                            share|improve this answer













                            protected void onPostExecute(JSONObject result) {
                            try {
                            if (result.length() != 0) {
                            Toast.makeText(getApplicationContext(), result.getString("message"), Toast.LENGTH_LONG).show();
                            Intent i = new Intent(getApplicationContext(), MainActivity.class);
                            startActivity(i);

                            } else {
                            Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show();
                            }
                            } catch (JSONException e) {
                            e.printStackTrace();
                            }
                            }






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 16 '18 at 7:05









                            Zameer Mullah JojnaZameer Mullah Jojna

                            63




                            63






























                                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%2f53332857%2fhow-to-open-mainactivity-after-login-success-with-php-massage%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