这是我的登录活动。 loginButtonListener声明一个AsyncTask变量来处理远程MySQL上的验证信息
public class LoginActivity extends AppCompatActivity implements AsyncResponse {
private EditText editText_email;
private EditText editText_password;
private Button button_login;
private Button button_register;
@Override
protected void onCreate(Bundle savedInstanceState) {
BackgroundWorker worker = new BackgroundWorker(LoginActivity.this);
loginButtonListener();
registerButtonListener();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
public void loginButtonListener(){
button_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String type = "login";
String email = editText_email.getText().toString();
String password = editText_password.getText().toString();
BackgroundWorker worker = new BackgroundWorker(LoginActivity.this);
worker.execute(type, email, password);
}
});
}
}
这是我的backgroundwork.class
public class BackgroundWorker extends AsyncTask<String,Void,String> {
Context context;
AlertDialog alertDialog;
public AsyncResponse delegate = null;
BackgroundWorker (Context ctx) {
context = ctx;
}
// Http MySQL stuffs
@Override
protected void onPreExecute() {
alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Login Status");
}
@Override
protected void onPostExecute(String result) {
//LoginActivity.get=result;
//delegate.processFinish(result);
alertDialog.setMessage(result);
alertDialog.show();
if(result.contains("Remote login success")){
Intent i = new Intent(LoginActivity.this, MainpanelActivity.class); // ERROR HERE, FIRST ARGUMENT IS NOT AN ENCLOSING CLASS
i.putExtra("email", this.email); /
startActivity(i);
}
}
}
然而,我得到了一个&#34; xxx不是一个封闭的类错误&#34;当我尝试开始一个新活动时,在onpostexecute()中(登录成功,跳转到另一个活动)
答案 0 :(得分:1)
您可以通过以下代码调用活动
amount_repositories.user_id