gpt4 book ai didi

安卓异步任务 : start new Activity in onPostExecute()

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:35:03 26 4
gpt4 key购买 nike

公共(public)类 HttpHelper 扩展 AsyncTask> { ArrayList list = new ArrayList();

@Override
protected ArrayList<String> doInBackground(String... urls) {
// TODO Auto-generated method stub

String result="";
for(String url:urls)
{
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
try
{
HttpResponse response = client.execute(request);
InputStream in = response.getEntity().getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line = null;
StringBuffer sb = new StringBuffer();
while((line = br.readLine())!=null)
{
sb.append(line+"\n");

}
in.close();
result = sb.toString();
String pageSource = new String(result);
int startindex = pageSource.indexOf("pdf_doc/");
String str="";
String []temp;
while(startindex !=-1)
{
int endindex = pageSource.indexOf(".pdf",startindex);
str = pageSource.substring(startindex+8, endindex);
String delimiter = "%20";
String value="";
temp = str.split(delimiter) ;
for(int i=0;i<temp.length;i++)
{
value= value+temp[i]+" ";

}

list.add(value);
startindex = pageSource.indexOf("pdf_doc/",endindex);
}
}


catch(Exception ex)
{
Log.e("Error in HTML Reading",ex.getMessage());

}

}

return list;

}

@Override
protected void onPostExecute(ArrayList<String> result) {
// TODO Auto-generated method stub

// Here i want to start new UI that use the result of AsyncTask
}

在这段代码中,我通过 AsyncTask 从服务器读取数据,结果应该在新的 UI 中。这意味着我想从 onPostExecute() 开始新的 Activity。

最佳答案

试试这个,

@Override
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
Intent intent = new Intent(MyAsyncTaskActivity.this, NextActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
}

关于安卓异步任务 : start new Activity in onPostExecute(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12332930/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com