Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Saving Activity state int String Array Double on Android


private int[] mData = new int[2]; // fill some values into array!!
    protected void onSaveInstanceState(Bundle outState) {
        outState.putBoolean("myBoolean", true);
        outState.putDouble("myDouble", 2.7);
        outState.putInt("myInt", 5);
        outState.putString("myString", "Heloo girls!");
       int[] data = new int[mData.length];
        for (int i = 0; i < data.length; i++) {
            data[i] = mData[i];
        outState.putIntArray("myArray", data);

public void onRestoreInstanceState(Bundle savedInstanceState) {
  boolean myBoolean = savedInstanceState.getBoolean("myBoolean", false); // false basic value
  double myDouble = savedInstanceState.getDouble("myDouble", 1.5); // 1.5 basic value
  int myInt = savedInstanceState.getInt("myInt", 10);
  String myString = savedInstanceState.getString("myString", "Hello boys!");
  int[] data = savedInstanceState.getIntArray("myArray");
  if (data != null && data.length == mData.length) {
            for (int i = 0; i < data.length; i++) {
                mData[i] = data[i];
public void onCreate(Bundle savedInstanceState) {
  boolean myBoolean =  savedInstanceState != null ? savedInstanceState.getBoolean("myBoolean", false) : true;
// etc.  .......

397LW NO topic_id


Další témata ....(Topics)


How to make a horizontal line in Android application example code | how-to-make-a-horizontal-line-in-android-application-example-code

In html is horizontal line a tag br. In Android source code you can use a View as xml example bellow.


at java.util.Arrays$ArrayList.get(Arrays.java:75) | at-java-util-arraysarraylist-getarrays-java75

Problem in Android application:

E/AndroidRuntime(416): FATAL EXCEPTION: main
E/AndroidRuntime(416): java.lang.IndexOutOfBoundsException
E/AndroidRuntime(416): 	at java.util.Arrays$ArrayList.get(Arrays.java:75)
E/AndroidRuntime(416): 	at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:298)
E/AndroidRuntime(416): 	at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:351)
E/AndroidRuntime(416): 	at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
E/AndroidRuntime(416): 	at android.widget.Spinner.makeAndAddView(Spinner.java:192)
E/AndroidRuntime(416): 	at android.widget.Spinner.layout(Spinner.java:151)
E/AndroidRuntime(416): 	at android.widget.Spinner.onLayout(Spinner.java:115)

Solution: check code for set and get selection

// Spinner _spin1 contain only  49 items 
// you can set max 48 ( range 0 - 48)
// 50 is IndexOutOfBoundsException

How to Add Home Screen Widgets on Your Android Phone | how-to-add-home-screen-widgets-on-your-android-phone

Long press by finger on screen
From dialogue select Widgets
Select your widget
Put your widget on the screen

Video tutorial - to add home screen widgets - Android 2.1


Android Studio reduce memory usage of PC | android-studio-reduce-memory-usage

File->Settings->Plugins and disable some plugins:

  • Google Cloud Testing

  • Google Cloud Tools Core

  • Google Cloud Tools for Android Studio

  • CVS Integration

  • Git Integration

  • GitHub

  • hg4idea

  • Subversion Integration

Use Emulator AVD with small memmory usage. For example: Virtual tablet with hight resolution have big memmory usage. Virtual phone with 240x320 resolution have small memmory usage.

Use instaed of Emulator, real device connected by USB (smarphone Samsung Galaxy or other recommended by Google whit debugable mode).

If you notice that Android Studio works slowly, consider the possibility to reduce the number of folders under antivirus protection.
Each antivirus check in your project consumes resources. You can significantly improve the performance, if you exclude certain folders from the antivirus protection.

Permission settings of Android application example | permission-settings-of-android-application-example

In your project AndroidManifest.xml you can set permission of Android application example source code.
For example if you want allow your application connection to INTERNET you have to permit this in AndroidManifest.xml.
WebViev show error: Website Not Available you have to permit INTERNET

        android:name="android.permission.INTERNET" />
        android:name="android.permission.GET_ACCOUNTS" />
        android:name="android.permission.USE_CREDENTIALS" />
        android:name="android.permission.MANAGE_ACCOUNTS" />
        android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
        android:name="android.permission.WRITE_SETTINGS" />
        android:name="android.permission.WRITE_SECURE_SETTINGS" />
        android:name="android.permission.READ_CONTACTS" />
        android:name="android.permission.WRITE_CONTACTS" />
        android:name="android.permission.READ_SYNC_STATS" />
        android:name="android.permission.READ_SYNC_SETTINGS" />
        android:name="android.permission.WRITE_SYNC_SETTINGS" />

Editace: 2016-03-02 08:15:58
Počet článků v kategorii: 397

11 Share