我有一个从看起来像这样的活动传递的字符串
@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);
在我的其他活动中,这就是我接收此字符串并将其编码到我的网址的方式。(et
如果您想知道的话,这只是我的editText)
@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";
我正在尝试移动代码以从我的doInbackGround
方法中接收这个字符串,它正在减慢速度,只是当我在下面移动时Intent in = getIntent();String searchTerm = in.getStringExtra("TAG_SEARCH");
出现onCreate
语法错误searchTerm
(asynctask 中的那个),上面写着“无法解析 searchTerm一个变量”。我曾尝试声明 Intent in = getIntent();String searchTerm = in.getStringExtra("TAG_SEARCH");
hasfinal
但它不会改变任何东西。我什至试过把它放进去onPreExecute
但它仍然没有改变任何东西。那么有人可以帮我解决这个致命的语法错误吗
这是我收到字符串的活动
@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<HashMap<String, String>>();
mTask = new LoadAllData();
mTask.execute();
}
@Override
public void onBackPressed()
{
/** If user Pressed BackButton While Running Asynctask
this will close the ASynctask.
*/
if (mTask != null && mTask.getStatus() != AsyncTask.Status.FINISHED)
{
mTask.cancel(true);
}
super.onBackPressed();
}
@Override
protected void onDestroy() {
if (mTask != null && 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<String, Void, JSONObject> {
@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;
}