私のアプリはまずcheckIndex()を呼び出します。インデックスがnullでない場合は、メイン画面に移動します。
共有設定に配列を保存します:
SharedPreferences prefs = getSharedPreferences(PRIVATE_PREF, 0);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(prog +"_size", prog.length);
for(int i=0;i<prog.length;i++)
editor.putString(prog + "_" + i, prog[i]);
editor.putInt("x", x);
editor.commit();
配列をコールバックするには、これを使用します:
int size = prefs.getInt(prog +"_size", 0);
String prog2[] = new String[size];
for(int i=0; i<prog2.length; i++)
prog2[i] = prefs.getString(prog + "_" + i, "");
prog=prog2;
int l = prefs.getInt("x", 0);
x=l;
textView1.setText(""+prog[x]);
logcat:
12-01 00:53:35.976: E/AndroidRuntime(6222): FATAL EXCEPTION: main
12-01 00:53:35.976: E/AndroidRuntime(6222): java.lang.ArrayIndexOutOfBoundsException: length=10; index=10
12-01 00:53:35.976: E/AndroidRuntime(6222): at com.example.perledisaggezza.MainActivity$6.onClick(MainActivity.java:428)
12-01 00:53:35.976: E/AndroidRuntime(6222): at android.view.View.performClick(View.java:4084)
12-01 00:53:35.976: E/AndroidRuntime(6222): at android.view.View$PerformClick.run(View.java:16966)
12-01 00:53:35.976: E/AndroidRuntime(6222): at android.os.Handler.handleCallback(Handler.java:615)
12-01 00:53:35.976: E/AndroidRuntime(6222): at android.os.Handler.dispatchMessage(Handler.java:92)
12-01 00:53:35.976: E/AndroidRuntime(6222): at android.os.Looper.loop(Looper.java:137)
12-01 00:53:35.976: E/AndroidRuntime(6222): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-01 00:53:35.976: E/AndroidRuntime(6222): at java.lang.reflect.Method.invokeNative(Native Method)
12-01 00:53:35.976: E/AndroidRuntime(6222): at java.lang.reflect.Method.invoke(Method.java:511)
12-01 00:53:35.976: E/AndroidRuntime(6222): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-01 00:53:35.976: E/AndroidRuntime(6222): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-01 00:53:35.976: E/AndroidRuntime(6222): at dalvik.system.NativeStart.main(Native Method)