忘れないように、よく使う小さな方法をメモしておきます
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();
}