登录成功后,我试图打开Mainactivity
E/flutter (14457): [ERROR:flutter/shell/common/shell.cc(188)] Dart Error: Unhandled exception:
E/flutter (14457): Looking up a deactivated widget's ancestor is unsafe.
E/flutter (14457): At this point the state of the widget's element tree is no longer stable. To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling inheritFromWidgetOfExactType() in the widget's didChangeDependencies() method.
来自PHP的“消息”:“已成功登录”和“错误的详细信息”
如果我更改:
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();
}
无论登录成功还是失败,都输入MainActivity 有人帮我
答案 0 :(得分:0)
根据您的代码,当结果对象不为null时,您将输入MainActivity。您应该添加更多条件来输入MainActivity,例如:
if (result != null && result.getString("result").equals("success"))
答案 1 :(得分:0)
您只是在检查if( [CONST1, CONST2].some(x=>path.match(x)) ) {...};
是否为空。您应该通过修改代码来检查登录的确切状态。
result
即使{message“的值为空,使用if (result != null && result.optString("message", "failed").equals("Successfully logged in"))
也可以。
注意::您可以根据JSON结构修改代码。
答案 2 :(得分:0)
将if条件替换为以下条件。
if (result != null && result.getString("message").contains("Successfully logged in"))
答案 3 :(得分:-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();
}
}