Toast消息未显示,收到警告:窗口已聚焦,忽略:com.android.internal.view的聚焦增益
下面是我的代码,它显示了一个进度对话框来验证用户。 我想在用户ID或密码不匹配时显示Toast消息(响应代码不是200) 但我得到一个警告Toast消息未显示,收到警告:窗口已聚焦,忽略:com.android.internal.view的聚焦增益,android,android-view,Android,Android View,下面是我的代码,它显示了一个进度对话框来验证用户。 我想在用户ID或密码不匹配时显示Toast消息(响应代码不是200) 但我得到一个警告 WARN/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy 并且不显示toast消息 代码 new Thread() { publi
WARN/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy
并且不显示toast消息
代码
new Thread() {
public void run() {
Looper.prepare();
try {
performBackgroundProcess();
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
}
}.start();
private void performBackgroundProcess() {
String sUserName = usernameEditText.getText().toString();
String sPassword = String authentication = sUserName + ":" + sPassword;
String login = Base64.encodeToString(authentication.getBytes(),
Base64.NO_WRAP);
Resources res = getResources();
String URLLogin = res.getString(R.string.URLlogin);
RestClient client = new RestClient(URLLogin, login);
try {
client.Execute(RequestMethod.POST);
} catch (Exception e) {
e.printStackTrace();
}
if (client.getResponseCode() != 200) {
progressDialog.dismiss();
Toast.makeText(getApplicationContext(),"Username or Password does not match",Toast.LENGTH_SHORT).show();
}
}
我认为您是在后台运行代码,所以Toast在那里不起作用。您必须在UI线程上而不是后台编写Toast。。因为此线程无法更新UI线程。。我建议您使用AsyncTask来处理其非常干净且易于使用的线程,而不是让作用域getApplicationcontext将其命名为“this”或“ActivityName.class”并进行检查。
没有检查它,但可能会工作。查看您想要的任何UI更改、toast、对话框,但不能在其他线程上进行。您必须在主UI线程上执行此操作。对您来说,一个简单的方法是使用handler,因为现在使用aync将需要进行许多更改
new Handler().post( new Runnable() {
public void run() {
progressDialog.dismiss();
Toast.makeText(getApplicationContext(),"Username or Password does not match",Toast.LENGTH_SHORT).show();
}
});
}
android.os的处理程序不是java的。this或ActivityName.class给出错误,我使用了ActivityName.this但不起作用据我所知,后台没有运行代码,得到响应后我想显示toast…无论如何,如果问题可以用异步任务解决,请给我举个例子,或者请编辑我的postvikky:by your code progressDialog保持运行,意味着这个thraed不运行。我已经在if(client.response!=200){ok.create活动中的处理程序实例,比如handler handler=new handler()