2012-01-27 31 views
1

當我使用startActivity(意向)加載設置爲Theme.Dialog我的應用程序爲主題的活動顯示Toast通知了Android :新活動的標籤。有沒有辦法關閉它?我發現,如果我跑在新的活動不會彈出吐司消息的OnCreate進度對話框,但我不想進度對話框或吐司消息。吐司與活動標籤彈出,當我使用startActivity(意向)與對話的主題活動

我所說的活性與:

Intent queriesIntent = new Intent(getApplicationContext(), GetQueriesPopup.class); 
startActivity(queriesIntent); 

而且我與Theme.Dialog活動:

public class GetQueriesPopup extends ListActivity { 
private static String server; 
private static String suffix; 
private static String project; 
private static int qid; 
private static String[] qidsArray; 
private static String username; 
private String[] queries; 
private ProgressDialog mDialog; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    final SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(this); 
    server = app_preferences.getString("server", "none"); 
    username = app_preferences.getString("username", "none"); 
    project = app_preferences.getString("project", "none"); 
    try 
    { 
     GetMap.showProgressDialog(true); 
     getRequest(); 
    } 
    catch(Exception ex) 
    { 
     GetMap.showProgressDialog(false); 
     AlertDialog alertDialog = new AlertDialog.Builder(this).create(); 
     alertDialog.setTitle("GTWeb"); 
     alertDialog.setMessage("Couldn't get a list of available queries, please check internet connection."); 
     alertDialog.setButton("OK", new DialogInterface.OnClickListener() 
     { 
      @Override 
      public void onClick(DialogInterface dialog, int which) 
      { 
       Intent intent = null; 
       intent = new Intent(getApplicationContext(), GTWeb.class); 
       intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
       startActivity(intent); 
      } 
     }); 
     alertDialog.show(); 
    } 

} 

     public void getRequest() 
{ 
    if (server.endsWith("/")) 
    { 
     suffix = "queries.aspx?usr=" + username + "&prj=" + project; 
    } 
    else 
    { 
     suffix = "/queries.aspx?usr=" + username + "&prj=" + project; 
    } 
    String url = server + suffix; 
    new HttpConnection().execute(url); 
} 

public void finishConnection(HttpConnection httpConn) 
{ 
    GetMap.showProgressDialog(false); 
    httpConn.cancel(true); 
    final SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(this); 
    try 
    { 
     setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, queries)); 
     LayoutParams dialogParams = this.getWindow().getAttributes(); 
     dialogParams.height = 500; 
     dialogParams.width = 500; 
     dialogParams.gravity = Gravity.BOTTOM | Gravity.LEFT; 
     dialogParams.dimAmount = 0; 
     this.getWindow().setAttributes(dialogParams); 
     } 
    catch(Exception ex) 
    { 
     Log.e("QueryFragment Exception", ex.toString()); 
     AlertDialog alertDialog = new AlertDialog.Builder(this).create(); 
     alertDialog.setTitle("GTWeb"); 
     alertDialog.setMessage("Couldn't get a list of available queries, please check internet connection."); 
     alertDialog.setButton("OK", new DialogInterface.OnClickListener() 
     { 
      @Override 
      public void onClick(DialogInterface dialog, int which) 
      { 
       Intent intent = null; 
       intent = new Intent(getApplicationContext(), GTWeb.class); 
       intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
       startActivity(intent); 
      } 
     }); 
     alertDialog.show(); 
    } 
    final ListView lv = getListView(); 
    lv.setOnItemClickListener(new OnItemClickListener() 
    { 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
     { 
      qid = position; 
      SharedPreferences.Editor editor = app_preferences.edit(); 
      Intent myIntent = null; 

myIntent = new Intent(view.getContext(), GetPromptsPopup.class); 
       editor.putInt("qid", Integer.valueOf(qidsArray[qid])); 
       editor.putBoolean("location", false); 
       editor.commit(); 
       startActivityForResult(myIntent, 1); 
      } 

    }); 
} 

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    if (resultCode == RESULT_OK) 
    { 
     if (data.getBooleanExtra("finish", false)) 
     { 
      this.finish(); 
     } 
    } 
} 


private class HttpConnection extends AsyncTask<String, Void, String[]> 
{ 
    protected String[] doInBackground(String... url) 
    { 
     int TIMEOUT_MILLISEC = 10000; //=10sec 
     HttpParams my_httpParams = new BasicHttpParams();; 
     HttpConnectionParams.setConnectionTimeout(my_httpParams, 
       TIMEOUT_MILLISEC); //set conn time out 
     HttpConnectionParams.setSoTimeout(my_httpParams, TIMEOUT_MILLISEC); 

     HttpClient client = new DefaultHttpClient(my_httpParams); 
     String userAgent = "GTI;Android;" + Build.VERSION.SDK_INT; 
     client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent); 
     HttpGet request = new HttpGet(url[0]); 
     String[] txtResponse = null; 
     try{ 
      HttpResponse response = client.execute(request); 
      txtResponse = TestHttpGet.requestQueries(response); 
     }catch(Exception ex){ 
      Log.e("QueryFragment Exception @HttpConnection", ex.toString()); 
     } 
     return txtResponse; 
    } 


    protected void onPostExecute(String[] theResults) 
    { 
     try 
     { 
     queries = new String[theResults.length]; 
     qidsArray = new String[theResults.length]; 
     for (int i = 0; i < theResults.length; i++) 
     { 
      String[] tempQueries = theResults[i].split("\\|", -1); 
      if (tempQueries.length > 1) 
      { 
       qidsArray[i] = tempQueries[0]; 
       queries[i] = tempQueries[1]; 
      } 
     } 
     //   queries = theResults; 
     finishConnection(this); 
     } 
     catch (Exception ex) 
     { 
      Log.e("QueryFragment Exception", ex.toString()); 
      AlertDialog alertDialog = new AlertDialog.Builder(getApplicationContext()).create(); 
      alertDialog.setTitle("GTWeb"); 
      alertDialog.setMessage("Couldn't get a list of available queries, please check internet connection."); 
      alertDialog.setButton("OK", new DialogInterface.OnClickListener() 
      { 
       @Override 
       public void onClick(DialogInterface dialog, int which) 
       { 
        Intent intent = null; 
        intent = new Intent(getApplicationContext(), GTWeb.class); 
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
        startActivity(intent); 
       } 
      }); 
      alertDialog.show(); 
     } 
    } 
} 

回答

1

我發現,它實際上是listActivity顯示的標題之前,我搬到/加載列表。我還沒有找到一種方法來擺脫它,所以我用ProgressDialog覆蓋它。