0

有这个网站,例如http://website.com你可以喜欢那里的东西,例如这样的链接:http ://website.com/3020/hype。您必须转到该链接才能获得喜欢的文章 (3020)。只有登录后才能点赞。

我有这个:

HttpClient client = new DefaultHttpClient();  
            String getURL = "http://website.com/3020/hype/";
            HttpGet get = new HttpGet(getURL);
            HttpResponse responseGet = client.execute(get, cookieStuff);

其中 cookieStuff 是我从登录中获得的 cookie 字符串。

这有效,但需要很长时间。还有其他选择吗?

4

1 回答 1

0

是的,还有另一个选项.. Internet 连接和数据库连接应该在 AyncTask 或 Handler 中进行。这将缩短连接时间(连接将在后台进行)..

这是异步任务的示例:

private class YourTask extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... s) {

        //Here you have to make the loading / parsing tasks
        //Don't call any UI actions here. For example a Toast.show() this will couse Exceptions
        // UI stuff you have to make in onPostExecute method

    }

    @Override
    protected void onPreExecute() {
        // This method will called during doInBackground is in process
        // Here you can for example show a ProgressDialog
    }

    @Override
    protected void onPostExecute(Long result) {
        // onPostExecute is called when doInBackground finished
        // Here you can for example fill your Listview with the content loaded in doInBackground method

    }

}

要执行 AsyncTask:

新的 YourTask().execute("");

于 2013-05-19T14:34:09.867 回答