0

I am defining an Intent inside of a protected function inside a private class. I am brand new to Java/Android and do not know how I pass the parameter to Intent. I have been using "this" in other Activities but I am getting a complaint from 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());
            }

        }

    }
silversunhunter
  • 1,219
  • 2
  • 12
  • 32

2 Answers2

3

You are in the inner class AsyncCaller so this refers to that class. You can use e.g. YourActivityClass.this if the outer class is named YourActivityClass to reference the outer class

Patrick
  • 33,984
  • 10
  • 106
  • 126
1

This refers there to the asynctask inatance.

Uae the activity or whatever that class is embeded in.

eduyayo
  • 2,020
  • 2
  • 15
  • 35