android - 当我将 startActivity(Intent) 与带有对话框主题的 Activity 一起使用时,Toast 会弹出带有 Activity 标签

标签 android toast

当我使用 startActivity(Intent) 加载主题设置为 Theme.Dialog 的 Activity 时,我的应用程序会显示一个带有 android:label 的新 Activity 的 Toast 通知。有没有办法关闭它?我注意到,如果我在新 Activity 的 onCreate 中运行进度对话框,它不会弹出 Toast 消息,但我不想要进度对话框或 Toast 消息。

我调用这个 Activity :

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

以及我对 Theme.Dialog 的 Activity :

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();
        }
    }
}

最佳答案

我发现它实际上是在我移动/加载列表之前显示的 listActivity 的标题。我还没有找到摆脱它的方法,所以我用 ProgressDialog 覆盖了它。

关于android - 当我将 startActivity(Intent) 与带有对话框主题的 Activity 一起使用时,Toast 会弹出带有 Activity 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9039697/

相关文章:

java - 尝试从 android 将图像上传到我的服务器

android - 从服务中的线程发送 toast

azure - 为什么 Toast 通知在 Windows 10 应用程序中使用 OnLaunched 而不是 OnActivated?

android - Toast 在 try/catch Thread.sleep() 之前不会显示

android - 依次显示多个 Toast 的问题

java - 如何在 Android 中使用 ShowcaseView 定位 ListView 中的元素?

java - Activity 不是封闭类(android studio)

Android TextView 追加到顶部

javascript - 使用 CSS、JS 和 asp.net 显示 toast

android - ShapeDrawable 椭圆形(描边样式)的边缘被切割 (Android Studio)