Android 在收到服务器的响应后完成活动
我希望在从另一个java类中的服务器收到完整响应时完成该活动 Category.java 这是主要活动Android 在收到服务器的响应后完成活动,android,android-activity,Android,Android Activity,我希望在从另一个java类中的服务器收到完整响应时完成该活动 Category.java 这是主要活动 public void onListItemClick(ListView parent, View v, int position, long id) { // Get the selected category id & name. String catId = ""; String catName = "";
public void onListItemClick(ListView parent, View v, int position, long id)
{
// Get the selected category id & name.
String catId = "";
String catName = "";
LinearLayout ll = (LinearLayout)findViewById(R.id.linearLayout1);
View view = ll.getChildAt(0);
if(view instanceof ListView) {
ListView lView = (ListView) view;
RowData rowData = (RowData) lView.getAdapter().getItem(position);
catId = rowData.mCatId;
catName = rowData.mTitle;
}
String url = "http://global.thinlenses.co.uk/virtualMirror/productlisting.php";
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<category><Id>" + catId + "</Id>"
+ "<Data>" + "pList" + "</Data></category>";
if(getIntent().getBooleanExtra("VM", false))
new SpinnerHelper().serverCall(Category.this, "ProductListVM", url, xml, catName);
else
new SpinnerHelper().serverCall(Category.this, "ProductList", url, xml, catName);
}
您可以为此使用上下文引用
Intent intent = new Intent(context,nextActivity.class);
context.startActivity(intent);
((Activity) context).finish();
您是否尝试过执行Category.this.finish()?是的,Category是activity,SpinnerHelper.java不是activity的常规类。
Handler handler = new Handler()
{
public void handleMessage(Message message)
{
if(isExecuted)
{
dialog.dismiss();
isExecuted = false;
if(result.equals("yes"))
{
/////HERE i want to start the next activity and finish the Category(previous activity).
}
Intent intent = new Intent(context,nextActivity.class);
context.startActivity(intent);
((Activity) context).finish();