public class SingleInstance {
private SingleInstance() {
}
public static SingleInstance getInstance() {
return SingleInstanceHolder.sInstance;
}
private static class SingleInstanceHolder {
private static SingleInstance sInstance = new SingleInstance();
}
}
Integer sum = 0;
for(int i=1000; i<5000; i++){
sum+=i;
}
int result = sum.intValue() + i; Integer sum = new Integer(result);
@Override public V put(K key, V value) {
if (key == null) {
return putValueForNullKey(value);
}
//some code here
// No entry for (non-null) key is present; create one
modCount++;
if (size++ > threshold) {
tab = doubleCapacity();
index = hash & (tab.length - 1);
}
addNewEntry(key, value, hash, index);
return null;
}
<activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar" android:configChanges="orientation" >
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.portrait_layout);
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
setContentView(R.layout.landscape_layout);
}
}
Log.i(LOGTAG, "onCreate bundle=" + savedInstanceState);
public void implicitUseStringBuilder(String[] values) {
String result = "";
for (int i = 0 ; i < values.length; i ++) {
result += values[i];
}
System.out.println(result);
}
private void printFileByLine(String filePath) {
try {
FileInputStream inputStream = new FileInputStream("textfile.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
br.close();
} catch(FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void printFileByLine(String filePath) {
if (!new File(filePath).exists()) {
return;
}
try {
FileInputStream inputStream = new FileInputStream("textfile.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
br.close();
} catch(FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void testThread() {
new Thread() {
@Override
public void run() {
super.run();
//do some io work
}
}.start();
}
public class AppConstants {
public static final int STATE_OPEN = 0;
public static final int STATE_CLOSE = 1;
public static final int STATE_BROKEN = 2;
@IntDef({STATE_OPEN, STATE_CLOSE, STATE_BROKEN})
public @interface DoorState {}
}
private void setDoorState(@AppConstants.DoorState int state) {
//some code
}
<service android:name=".NetworkService" android:process=":network" />
public class MyApplication extends Application {
private static final String LOGTAG = "MyApplication";
@Override
public void onCreate() {
String currentProcessName = getCurrentProcessName();
Log.i(LOGTAG, "onCreate currentProcessName=" + currentProcessName);
super.onCreate();
if (getPackageName().equals(currentProcessName)) {
//init for default process
} else if (currentProcessName.endsWith(":network")) {
//init for netowrk process
}
}
private String getCurrentProcessName() {
String currentProcessName = "";
int pid = android.os.Process.myPid();
ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
if (processInfo.pid == pid) {
currentProcessName = processInfo.processName;
break;
}
}
return currentProcessName;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有