// http地址
String httpUrl = "http://192.168.1.148:8080/Read/userLogin?user_phone="
+ Name;
System.out.println(httpUrl);
resultData = "";
URL url = null;
try {
url = new URL(httpUrl);
HttpURLConnection urlConn = (HttpURLConnection) url
.openConnection();
inStream = urlConn.getInputStream(); if (urlConn.getResponseCode() == 200) { InputStreamReader in = new InputStreamReader(
inStream); // 为输出创建BufferedReader
BufferedReader buffer = new BufferedReader(in);
String inputLine = null;
// 使用循环来读取获得的数据
while (((inputLine = buffer.readLine()) != null)) {
// 我们在每一行后面加上一个"\n"来换行
resultData += inputLine;
}
in.close();
Log.i("ok", "ok"); // 关闭http连接
urlConn.disconnect();
ByteArrayInputStream bis = new ByteArrayInputStream(
resultData.getBytes());
list = SAXxml.readXML(bis);
if (list != null && list.size() > 0) {
String result = list.get(0).loginResult;
if (result.equals("1")) { Toast.makeText(getApplication(), "登录成功",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Main.this,
Contact_list.class);
intent.putExtra("contactList", list);
startActivity(intent);
Main.this.finish();
} else if (result.equals("2")) {
Toast.makeText(getApplicationContext(),
"用户未注册", Toast.LENGTH_SHORT).show();
}
}
}
} catch (ClientProtocolException e) {
Toast.makeText(getApplication(), e.toString(),
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(getApplication(), "访问服务器失败请重试",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getApplication(), e.toString(),
Toast.LENGTH_SHORT).show();
}请问该怎样把进度条加进去 并实现两个activity之间的跳转
String httpUrl = "http://192.168.1.148:8080/Read/userLogin?user_phone="
+ Name;
System.out.println(httpUrl);
resultData = "";
URL url = null;
try {
url = new URL(httpUrl);
HttpURLConnection urlConn = (HttpURLConnection) url
.openConnection();
inStream = urlConn.getInputStream(); if (urlConn.getResponseCode() == 200) { InputStreamReader in = new InputStreamReader(
inStream); // 为输出创建BufferedReader
BufferedReader buffer = new BufferedReader(in);
String inputLine = null;
// 使用循环来读取获得的数据
while (((inputLine = buffer.readLine()) != null)) {
// 我们在每一行后面加上一个"\n"来换行
resultData += inputLine;
}
in.close();
Log.i("ok", "ok"); // 关闭http连接
urlConn.disconnect();
ByteArrayInputStream bis = new ByteArrayInputStream(
resultData.getBytes());
list = SAXxml.readXML(bis);
if (list != null && list.size() > 0) {
String result = list.get(0).loginResult;
if (result.equals("1")) { Toast.makeText(getApplication(), "登录成功",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Main.this,
Contact_list.class);
intent.putExtra("contactList", list);
startActivity(intent);
Main.this.finish();
} else if (result.equals("2")) {
Toast.makeText(getApplicationContext(),
"用户未注册", Toast.LENGTH_SHORT).show();
}
}
}
} catch (ClientProtocolException e) {
Toast.makeText(getApplication(), e.toString(),
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(getApplication(), "访问服务器失败请重试",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getApplication(), e.toString(),
Toast.LENGTH_SHORT).show();
}请问该怎样把进度条加进去 并实现两个activity之间的跳转
我是想让http连接作为后台运行
该怎样解决
try {
mWebView.loadUrl("http://**********");
thread=new Thread(this);
thread.start();
} catch (Exception e) {
e.printStackTrace();
}
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int newProgress) {
NewsInformation.this.getWindow().setFeatureInt(
Window.FEATURE_PROGRESS, newProgress * 100);
process = newProgress;
super.onProgressChanged(view, newProgress);
}
});
}
@Override
public void run() {
// TODO Auto-generated method stub
while (running) {
Message m = new Message();
if (process >= 100) {
m.what = NewsInformation.GUI_STOP_NOTIFIER;
NewsInformation.this.myMessageHandler.sendMessage(m);
} else {
m.what = NewsInformation.GUI_THREADING_NOTIFIER;
NewsInformation.this.myMessageHandler.sendMessage(m);
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Handler myMessageHandler = new Handler() {
// @Override
public void handleMessage(Message msg) {
switch (msg.what) {
case NewsInformation.GUI_STOP_NOTIFIER:
m_ProgressBar.setVisibility(View.GONE);
mWebView.setVisibility(View.VISIBLE);
textview.setVisibility(View.GONE);
running = false;
Thread.currentThread().interrupt();
break;
case NewsInformation.GUI_THREADING_NOTIFIER:
if (!Thread.currentThread().isInterrupted()) {
m_ProgressBar.setProgress(process);
m_ProgressBar.setSecondaryProgress(process);
}
break;
}
super.handleMessage(msg);
}
};