How to open Mainactivity after login success with PHP massage?
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
add a comment |
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
Check out this project on github. It also uses login and signup in both the apps.
– Sayok Majumder
Nov 16 '18 at 7:51
add a comment |
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
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
php
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
add a comment |
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
add a comment |
4 Answers
4
active
oldest
votes
Replace your if condition with below condition.
if (result != null && result.getString("message").contains("Successfully logged in"))
add a comment |
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"))
Sorry mate, by mistake I modified your answer instead of me. Reverting.
– Rohit5k2
Nov 16 '18 at 7:09
add a comment |
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.
add a comment |
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();
}
}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Replace your if condition with below condition.
if (result != null && result.getString("message").contains("Successfully logged in"))
add a comment |
Replace your if condition with below condition.
if (result != null && result.getString("message").contains("Successfully logged in"))
add a comment |
Replace your if condition with below condition.
if (result != null && result.getString("message").contains("Successfully logged in"))
Replace your if condition with below condition.
if (result != null && result.getString("message").contains("Successfully logged in"))
answered Nov 16 '18 at 7:04
JoyJoy
315
315
add a comment |
add a comment |
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"))
Sorry mate, by mistake I modified your answer instead of me. Reverting.
– Rohit5k2
Nov 16 '18 at 7:09
add a comment |
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"))
Sorry mate, by mistake I modified your answer instead of me. Reverting.
– Rohit5k2
Nov 16 '18 at 7:09
add a comment |
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"))
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"))
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 16 '18 at 7:14
answered Nov 16 '18 at 7:04
Rohit5k2Rohit5k2
14.6k42752
14.6k42752
add a comment |
add a comment |
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();
}
}
add a comment |
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();
}
}
add a comment |
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();
}
}
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();
}
}
answered Nov 16 '18 at 7:05
Zameer Mullah JojnaZameer Mullah Jojna
63
63
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Check out this project on github. It also uses login and signup in both the apps.
– Sayok Majumder
Nov 16 '18 at 7:51