Java/Android不允许将“this”作为意图声明中的参数
我在私有类中的受保护函数中定义意图。我是Java/Android新手,不知道如何将参数传递给Intent。我一直在其他活动中使用“this”,但我收到AndroidStudio的投诉
Intent setSession = new Intent(this, posterSessionSetup.class);
Cannot resolve constructor Intent(.....
private class AsyncCaller extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
//get the text input and validate it
EditText userName = (EditText)findViewById(R.id.txtUserName);
EditText password = (EditText)findViewById(R.id.passWord);
return readJSONFeed("mywebservice", userName.getText().toString(), password.getText().toString());
}
protected void onPostExecute(String result){
try {
JSONObject jsonObject = new JSONObject(result);
JSONObject r = new JSONObject(jsonObject.getString("r"));
String status = r.getString("status");
String msg = r.getString("msg");
if (status == "complete"){
--------->>>>>> Intent setSession = new Intent(this, posterSessionSetup.class);
startActivity(setSession);
}
else {
Toast.makeText(getBaseContext(), r.getString("status") + ":" + r.getString("msg"), Toast.LENGTH_SHORT).show();
}
} catch(Exception e){
Log.d("Read Json File", e.getLocalizedMessage());
}
}
}
# 1 楼答案
这里指的是异步任务
Uae活动或该类嵌入的任何内容
# 2 楼答案
你在the inner class
AsyncCaller
所以this
指的是那个类。如果外部类名为YourActivityClass
,则可以使用YourActivityClass.this
来引用外部类