Switch Statement Java basic example
Switch statement with numbers and array of strings Java example.
Possible:
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "One", "Two", "Three", "Four" };
int i = 2;
switch (i) {
case 1: {
System.out.println(arrayOfString[i]);
break;
}
case 2: {
System.out.println(arrayOfString[i]);
break;
}
case 3: {
System.out.println(arrayOfString[i]);
break;
}
default: {
System.out.println("Enter a valid value.");
}
} // END of switch
}
}
/*
* Three
*/
Possible:
case 1:
System.out.println(arrayOfString[i]);
break;
// i love this notation
case 1:{
System.out.println(arrayOfString[i]);
}break;
case 1:{
System.out.println(arrayOfString[i]);
break;
}
396LW NO topic_id
AD
Další témata ....(Topics)
Insert into your default start up activity tag inten-filter tag with action MAIN and category LAUNCHER
AndroidManifest.xml
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="//schemas.android.com/apk/res/android"
package="com.example.blabol"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
If you have trouble with compilation of new project after you make a update of android development tools you can go back to old version of the tools.
-
- Open Help > About Eclipse... use the menu > About...
- Click the "Installation Details" button.
- Select the "Installation History" tab.
- Select one of the previous configurations.
- Click the "Revert" button at the bottom.
Warning: The application may be doing too much work on its main thread
Try this sorce code:
Try this sorce code:
import android.os.StrictMode;
public class MyActivity extends Activity {
static{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
@Override
public void onCreate(Bundle savedInstanceState) {
//.................. etc.
On Android device is path to *.apk like this example:
How get package *.apk path on device dynamically Android example
/data/app/cz.okhelp.my_package.apk
How get package *.apk path on device dynamically Android example
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String sPackagePath = getPackageResourcePath();
}
Bitmap size calculation:
bmpHeight * bmpWidth
For example:
Resolution of image 1024x860 = 880 640 pixels
If every pixel get 4 byte of memory:
880 640x4= 3 522 560 (3.5MB)
Get bitmap size without allocation of memory:
Get Memory size:
Make your bitmap not bigger as maxMemory size
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
bmpHeight * bmpWidth
For example:
Resolution of image 1024x860 = 880 640 pixels
If every pixel get 4 byte of memory:
880 640x4= 3 522 560 (3.5MB)
Get bitmap size without allocation of memory:
BitmapFactory.Options options = new BitmapFactory.Options();
// If set to true, the decoder will return null (no bitmap), but the out... fields will still
// be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.drawable.my_image, options);
int imageHeight = options.outHeight; // 1024
int imageWidth = options.outWidth; // 860
String imageType = options.outMimeType; // .jpg .png .gif
Get Memory size:
Make your bitmap not bigger as maxMemory size
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
float density = getResources().getDisplayMetrics().density;
Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
Debug.getMemoryInfo(memoryInfo);
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int freeMemory = (int) (Runtime.getRuntime().freeMemory() / 1024);
String memMessage = String.format(
"Free=%d kB,
MaxMem=%d kB,
Memory: Pss=%.2f MB, Private=%.2f MB, Shared=%.2f MB",
freeMemory,
maxMemory,
memoryInfo.getTotalPss() / 1024.0,
memoryInfo.getTotalPrivateDirty() / 1024.0,
memoryInfo.getTotalSharedDirty() / 1024.0);
((TextView)findViewById(R.id.textViewInfo)).setText(memMessage );
Editace: 2011-10-05 08:01:22
Počet článků v kategorii: 396
Url:switch-statement-java-basic-example