Note that there are some explanatory texts on larger screens.

plurals
  1. POReceiving passed String
    primarykey
    data
    text
    <p>I have a string that I passed from an activity that looks this </p> <pre><code> @Override public void onClick(View v) { ...... String searchTerm = et.getText().toString().trim(); Intent in = new Intent(PassingString.this, RecieveString.class); in.putExtra("TAG_SEARCH", searchTerm); startActivity(in); </code></pre> <p>In my other activity this is how I receive this string and encode it to my web address. (<code>et</code> is just my editText in case you where wondering) </p> <pre><code> @Override protected JSONObject doInBackground(String... args) { .... Intent in = getIntent(); String searchTerm = in.getStringExtra("TAG_SEARCH"); String query = URLEncoder.encode(searchTerm, "utf-8"); String URL = "http://example.com"+ query + "json"; </code></pre> <p>I am trying to move the code to receive this string out of my <code>doInbackGround</code> method it is slowing things down its just that when I move <code>Intent in = getIntent();String searchTerm = in.getStringExtra("TAG_SEARCH");</code> under <code>onCreate</code> I get an syntax error underneath <code>searchTerm</code> (the one that is in the asynctask) that says "searchTerm cannot be resolved to a variable". I had tried declaring <code>Intent in = getIntent();String searchTerm = in.getStringExtra("TAG_SEARCH");</code> has <code>final</code> but it doesn't change anything. I have even tried putting it in in <code>onPreExecute</code> but it still doesn't change anything. So can somebody please help me solve this killer syntax error</p> <p>here is the activity where I am receiving the string </p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.listview); Intent in = getIntent(); String searchTerm = in.getStringExtra("TAG_SEARCH"); questionList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); mTask = new LoadAllData(); mTask.execute(); } @Override public void onBackPressed() { /** If user Pressed BackButton While Running Asynctask this will close the ASynctask. */ if (mTask != null &amp;&amp; mTask.getStatus() != AsyncTask.Status.FINISHED) { mTask.cancel(true); } super.onBackPressed(); } @Override protected void onDestroy() { if (mTask != null &amp;&amp; mTask.getStatus() != AsyncTask.Status.FINISHED) { mTask.cancel(true); } super.onDestroy(); } @Override protected void onPause() { if (pDialog != null) { if(pDialog.isShowing()) { pDialog.dismiss(); } super.onPause(); } } class LoadAllData extends AsyncTask&lt;String, Void, JSONObject&gt; { @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(ListView.this); pDialog.setMessage("Loading Data. Please wait..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } @Override protected JSONObject doInBackground(String... args) { JSONObject json = new JSONObject(); try { String query = URLEncoder.encode(searchTerm, "utf-8"); String URL = "http://example.com"+ query + "json"; JSONParsser jParser = new JSONParsser(); json = jParser.readJSONFeed(URL); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return json; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload