Reputation: 33
My problem is that this won't work:
if (result.equals("success")) {
Toast.makeText(MainActivity.myContext, "Hausaufgabe eingetragen!", Toast.LENGTH_LONG).show();
startSync(lv);
}
else if (result.equals("already exists")) {
Toast.makeText(MainActivity.myContext, "Hausaufgabe wurde bereits eingetragen!", Toast.LENGTH_LONG).show();
}
else if (result.equals("user not exists")){
Toast.makeText(MainActivity.myContext, "Das eingespeicherte Benutzerkonto ist ungültig oder gelöscht worden!", Toast.LENGTH_LONG).show();
}
else if (result.equals("server problem")){
Toast.makeText(MainActivity.myContext, "Ein Server Problem ist aufgetreten!\n" + "Bitte melden!", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(MainActivity.myContext, "Unbekannte Rückmeldung des Servers:\n" + result, Toast.LENGTH_LONG).show();
}
Log.d("API",result);
LogCat says API:success, but feedback in the app is "Unbekannte Rückmeldung des Servers: success"
Upvotes: 1
Views: 155
Reputation: 126455
Use the trim()
method, because your variable result
probably contains an space, like " success":
if (result.trim().equals("success")) {
...
...
you could complement with toLowerCase()
method, to prevent the handle of capitalized letters like " Success":
if (result.trim().toLowerCase().equals("success")) {
...
...
or try using indexOf()
method
for example:
if (result.indexOf("success") > 0) {
...
...
Upvotes: 2