常用的小方法,避免忘记,在此记录一下
16lz
2021-01-23
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 stubsuper.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数据作为参数,传递给另一个activityi.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();}
更多相关文章
- android中的bundle传送数据
- Android Room联合AsyncListUtil实现RecyclerView分页加载ORM数据
- 重写对话框
- Android中Dialog对话框
- Android——SQLite数据库
- Android使用JDBC连接mysql数据库
- Android 高效的SQLite型数据库greenDAO使用