以下是仅在我尝试调用方法 soapPHP() 时才会产生异常的代码,否则它会完美运行。经过多次尝试解决这个问题,我现在筋疲力尽。你们的任何帮助都将不胜感激。
private ProgressDialog pd;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
ThemeUtils.sTheme = ThemeUtils.THEME_BLUE;
ThemeUtils.onActivityCreateSetTheme(MainMenuActivity.this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main_menu_screen);
asynThread = new AsynThread();
handler = new Handler()
{
@Override
public void dispatchMessage(Message msg)
{
super.dispatchMessage(msg);
dispLayMsg(globalMessage);
}
};
asynThread.execute(GET_MAIN_MENU);
}
--
public Object soapPHP(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL)
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("yourName", "Mohsin");
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.debug = true;
Object response = null;
try {
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
}
catch (Exception e)
{
}
return response;
}
--
public class AsynThread extends AsyncTask<String, Void, String>
{
private String inputParam = "";
@Override
protected void onPreExecute()
{
// TODO Auto-generated method stub
super.onPreExecute();
pd = ProgressDialog.show(MainMenuActivity.this, "Attention..",
"Please wait");
}
@Override
protected String doInBackground(String... params)
{
// TODO Auto-generated method stub
inputParam = params[0];
if (inputParam.equalsIgnoreCase(GET_MAIN_MENU))
{
menu_adapter = new MenuListAdapter();
MenuListItem item = new MenuListItem();
item.setMenu_name("Menu");
item.setMenu_desc("Menu Description");
menu_adapter.add(item);
Object obj = soapPHP(METHOD_NAME, SOAP_ACTION, NAMESPACE, URL);
menu_adapter.add(item);
menu_list = (ListView) findViewById(R.id.main_menu_list);
menu_list.setAdapter(menu_adapter);
}
return null;
}
@Override
protected void onPostExecute(String result)
{
// TODO Auto-generated method stub
super.onPostExecute(result);
pd.dismiss();
/*
* if (inputParam.equalsIgnoreCase(UPLOAD)) { // uploadData(); }
*/
}
}
--
LogCat 中的异常:
07-30 17:51:10.882: E/WindowManager(5916): android.view.WindowLeaked: Activity com.tgu.sample.onlinemenu.ui.MainMenuActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4052db78 that was originally added here