1. 将Activity设置为对话框模式
例如:
2. 设置Activity的进度条
3. Activity之间传递数据
4. int String 之间的转换
5. HttpURLConnection连接超时设置
例如:
<activity android:name=".DeviceListActivity"
android:theme="@android:style/Theme.Dialog"
android:configChanges="orientation|keyboardHidden" />
2. 设置Activity的进度条
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.loading);
}
setProgressBarIndeterminateVisibility(true); //打开
setProgressBarIndeterminateVisibility(false); //关闭
3. Activity之间传递数据
//第一个activity,发送
Intent i = new Intent();
i.setClass(LoadingActivity.this, DetailsInfo.class);
Bundle bundle = new Bundle();
bundle.putString("xml", strXML); //xml数据作为参数,传递给另一个activity
i.putExtras(bundle);
startActivity(i);
//第二个activity,接收
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle bunde = this.getIntent().getExtras();
String strXML = bunde.getString("xml");
}
4. int String 之间的转换
// String转换为int
int i = Integer.parseInt([String]); 或
i = Integer.parseInt([String],[int radix]);
int i = Integer.valueOf(my_str).intValue();
// int转换为String
String s = String.valueOf(i);
String s = Integer.toString(i);
String s = "" + i;
5. HttpURLConnection连接超时设置
URL url = null;
HttpURLConnection urlConn = null;
url = new URL(AppConstant.URL.Url_AgtTotalInfo);
urlConn = (HttpURLConnection) url.openConnection();
urlConn.setConnectTimeout(10 * 1000);
System.out.println("time out is 10 seconds");
try{
if (urlConn.getResponseCode() != 200){
throw new SocketTimeoutException("request url failed!");
}
}catch(SocketTimeoutException e){
System.out.println(e);
// System.out.println("not connected");
urlConn.disconnect();
}