我在我的Android应用程序中使用此代码,我在MainActivity中调用函数userExists(),这是一个不同的类。这是我的代码:
public boolean userExists(Member m){
final String sqlQuery = "SELECT * FROM `users` WHERE `email` = '"+m.getEmail().toString()+"'";
Log.d("InsideUserExists", "Member "+m.getEmail()+" and "+m.getPassword());
Handler handler = new Handler();
final boolean value;
Thread th = new Thread(new Runnable() {
@Override
public void run() {
try{
Log.d("userExists", Integer.toString(new Query().getUserQuery(sqlQuery)));
}catch(Exception e){
System.out.println("Exception caught while getting "+e);
}
}
});
th.start();
return false;
}
以下是我从MainActivity调用此函数的方法:
public void generateQR(View v){
final Intent intent = new Intent(MainActivity.this,QRGenActivity.class);
final EditText mEdit = (EditText) findViewById(R.id.email);
final EditText mPass = (EditText) findViewById(R.id.password);
Member m = new Member(mEdit.getText().toString(),mPass.getText().toString());
new AsyncTask<String, String, String>() {
protected String doInBackground(String... params) {
if(new Functions().userExists(new Member(mEdit.getText().toString(),mPass.getText().toString()))){
return "done";
} else return null;
};
protected void onPostExecute(String result) {
if(result!=null){
Log.d("ProceedWithIntent","Proceed to get to next activity");
intent.putExtra("emailValue", mEdit.getText().toString());
intent.putExtra("password", mPass.getText().toString());
startActivity(intent);
}
};
}.doInBackground(mEdit.getText().toString(),mPass.getText().toString());
}
我的问题是,正如你所看到的,userExists()必须返回类型“boolean”,并且我使用new Query().getUserQuery(sqlQuery)
查询用户,该用户根据是否有任何记录返回int,但是,这是在Runnable()中。
如何将此整数值从getUserQuery()函数调用传递给外部userExists()方法,以便根据int值返回true或false。
由于