如何从onPostExecute调用新活动?

时间:2015-11-13 16:36:13

标签: android android-intent android-activity

protected String doInBackground(String... args) {

        String myres = null;
        String bot_string = args[0] ;
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("question", bot_string));


        JSONObject json = jsonParser.makeHttpRequest(url_pythonwebservice, "GET", params);

        // Check your log cat for JSON reponse
        Log.d("results: ", json.toString());


        try {



            myres = json.getString(TAG_BOTRESPONSE);


        } catch (JSONException e) {
            e.printStackTrace();
        }


        return myres;



    }

 protected void onPostExecute(String file_url) {

        pDialog.dismiss();



        Toast.makeText(getApplicationContext(),file_url , Toast.LENGTH_LONG).show();


        //Get reference to textview above in oncreate method
        //bot.setText(file_url);

    }


 if (file_url == "Navigation"){

            Intent i = new Intent(Voice.this, MapsActivity.class);
            startActivity(i);
        }

Toast正在打印。我想调用MapsActivity.class if file_url == "Navigaion"但是如果我放入onPostExecute,这就不行了。我该如何致电MapsActivity.class。这是一个语音识别应用程序。

1 个答案:

答案 0 :(得分:0)

在Java中,您应该将两个字符串比较为

if(string1.equals(string2))
 {
   // code block
 }

因此,对于您的示例,您应该更改代码,

if (file_url.equals("Navigation"))
{
  // more code follows
}