Android SDKã®ï¼Parcelableã¨Serializableã®éããæ¯è¼ - Intentã§ç¬èªãªãã¸ã§ã¯ããéæ¬ããéï¼å½¹ç«ã¤ã®ã¯ã©ã¡ãï¼
éè¦ãªãç¥ããï¼
ãã®è¨äºã§å ¬éããæ å ±ã¯ï¼Androidã®MVCãã¬ã¼ã ã¯ã¼ã¯ãAndroid-MVCãã®æ©è½ã®ä¸é¨ã¨ãã¦åãè¾¼ã¾ãã¾ããã
ããæ£ç¢ºãªè¨è¨æ å ±ãï¼åä½å¯è½ãªå ¨ã½ã¼ã¹ã³ã¼ããé²è¦§ãããå ´åï¼ãAndroid-MVCãã®å ¬å¼ãã¼ã¸ããæè¡æ å ±ãåç §ãã¦ãã ããã
Androidã®MVCãã¬ã¼ã ã¯ã¼ã¯ - ãAndroid-MVCã
http://code.google.com/p/android-mvc-...
Androidã¢ããªã®ç»é¢é·ç§»æã«ã¯ï¼
Intentãªãã¸ã§ã¯ãå ã«putExtra()ã§ãã¼ã¿ãè©°ãè¾¼ãã§ï¼æ¬¡ã®ç»é¢ã«æ¸¡ãã
Intentã«å¯¾ãã¦Stringã¨ãintã¨ãï¼ããªããã£ããªå¤ãæ ¼ç´ããã®ã¯å®¹æã ã
ãããï¼æ ¼ç´ããå¤ã®ãã¼ã¿æ§é ãè¤éã«ãªã£ã¦ããã¨ï¼
ç¬èªãªãã¸ã§ã¯ãã®ã¤ã³ã¹ã¿ã³ã¹ã丸ãã¨æ ¼ç´ããããªãã
ã©ãããã°å¯è½ãã
ãã®å ´åï¼ãªãã¸ã§ã¯ãã®ãç´ååï¼ã·ãªã¢ã©ã¤ãºï¼ãã®ææ³ããã¼ã«ãªãã
- ï¼ï¼ï¼Serializableã¨Parcelableã«ã¤ãã¦ã®èæ¯æ å ±
- ï¼ï¼ï¼Parcelableã§intå¤ãï¼ã¤ã ãéæ¬ãããµã³ãã«ã³ã¼ã
- ï¼ï¼ï¼éParcelableãªãã¸ã§ã¯ããï¼Parcelableãªãã¸ã§ã¯ãã«æ ¼ç´ããã¨ã©ããªãã
- ï¼ï¼ï¼ã·ã³ãã«ãªSerializableãæãç¡é£ã
- ï¼ï¼ï¼ã¤ã³ãã¼ã¯ã©ã¹ãSerializableã«ãããæã®è©¦ç·´
- æ¯è¼ã¨çµè«
ï¼ï¼ï¼Serializableã¨Parcelableã«ã¤ãã¦ã®èæ¯æ å ±
è¦ç´ï¼
- ãªãã¸ã§ã¯ããSerializableã«ããã°ï¼ã¢ããªå ãé£ã¶Intentä¸ã«ï¼ãªãã¸ã§ã¯ããç´æ¥ä¹ã£ããäºãã§ããã
- ãªãã¸ã§ã¯ããParcelableã«ããã°ï¼ã¢ããªéãã¾ããäºãã§ããããã ããã®åï¼ç´ååã®å¦çãèªåã§ã³ã¼ãã£ã³ã°ããå¿ è¦ãããã
Androidä¸ã§ã®Serializableã®å©ç¨ã«é¢ããåèæ
å ±ï¼
Androidã®ç»é¢é·ç§» Intentã使ã£ã¦objectã渡ãæ¹æ³
http://d.hatena.ne.jp/hidecheck/20091...
- é常ã«ç°¡åãªãµã³ãã«ã³ã¼ã
Android: Difference between Parcelable and Serializable?
http://stackoverflow.com/questions/33...
- Serializable is a standard Java interface.
- Parcelable is an Android specific interface where you implement the serialization yourself. (èªåã§ç´ååããåï¼ããã©ããªãã)
- However, you can use Serializable objects in Intents.
Parcelableã®å©ç¨ãå§ããæè¡è³æããµã³ãã«ã³ã¼ãéï¼
Intent 㧠Parcelable ãå®è£ ããèªä½ãªãã¸ã§ã¯ãã®åã渡ãããã¦ã¿ã
http://rtaki.blogspot.com/2011/01/int...
- Intentã«ã¯putExtra(String name, Parcelable value) 㨠getParcelableExtra(String name) ããã
- Parcelable ãèªä½ã¯ã©ã¹ã«é©ç¨ããã°ï¼ Activity éã§ãªãã¸ã§ã¯ãã®åã渡ããã§ãã
[Android] android.os.Parcelable / Parcel
http://www.adakoda.com/adakoda/2009/0...
- Parcelableã¤ã³ã¿ãã§ã¼ã¹ãå®è£ ãã¦ããã¯ã©ã¹ã§ããã°ããã®ã¤ã³ã¹ã¿ã³ã¹ããputExtra(String name, Parcelable value)ãå¼ã³åºããã¨ã§ãã¤ã³ã¹ã¿ã³ã¹ãã¨æ¸¡ããã¨ãã§ãã
AndroidãParcelable ã使ã£ã¦ã¯ã©ã¹ã®ã¡ã³ããä¸æä¿å
http://y-anz-m.blogspot.com/2010/03/a...
- ãç¬èªã«ãã¼ã¿ã¯ã©ã¹ãç¨æãã¦ãã¦ããã®ã¯ã©ã¹ã®ã¡ã³ããã¨ä¿åããããã ãã©â¦ãã¨ããå ´åã«ç»å ´ããã®ã Parcelable
- Parcelableã¯Parcel ã«ãã¼ã¿ãæ¸ãï¼èªã¿ããããã®ã¤ã³ã¿ãã§ã¼ã¹
Androidã¢ããªå ¥é No.65 Intent ã¢ã¯ã·ã§ã³ã§ãã¼ã¿ãåãåã Parcelable
http://d.hatena.ne.jp/kuwalab/2011020...
- Parcelã¨ããåèªã¯å°å ã¨ããæå³ããã¼ã¿ãã¾ã¨ãã¦æ¸¡ããããªãã®ãã¤ã¡ã¼ã¸
- Serializableã§ã¯åä¸ã®ã¢ããªã±ã¼ã·ã§ã³ã§ã®æ示çãªIntentã§ããã°åé¡ãªãããããæé»çãªIntentã®å ´åï¼èªåãä½æããActivityãã¢ã¯ã·ã§ã³ãåãåãã¨ã¯éããªãããªã®ã§Serializeãããªãã¸ã§ã¯ãã復å ã§ããä¿è¨¼ã¯ãªãã
- Parcelableã使ç¨ãããã¨ã§ï¼ã¢ããªéã§ãªãã¸ã§ã¯ãã®ãããªãã®ã®åã渡ãããããã¨ãã§ãããã¢ããªéã§Parcelableã¯ã©ã¹ã®å®ä½ãç°ãªã£ã¦ãæ§ããªãã
Android Developers : Parcelable
http://developer.android.com/intl/ja/...
- å©ç¨æã¯ï¼Parcelable.Creatorã¤ã³ã¿ãã§ã¼ã¹ãå®è£ ãããCREATORãã¨ããååã®ãã£ã¼ã«ããå¿ è¦
- âããã ãã§ã¯ä½ã®ãã¨ãä¼ãã¥ããã®ã§ï¼ãµã³ãã«ã³ã¼ããåç §ã®ãã¨ã
ï¼ï¼ï¼Parcelableã§intå¤ãï¼ã¤ã ãéæ¬ãããµã³ãã«ã³ã¼ã
ä¸è¿°ã®æ å ±ãè¸ã¾ãã¦ï¼ã¾ãã¯é©ç¨ç¯å²ãåºãã¦ä¾¿å©ãããªParcelableã®ãµã³ãã«ã³ã¼ãã
ç»é¢é·ç§»ã®ä»æ§ã¨ãã¦ã¯ï¼InputActivityããResultActivityã«å¯¾ãã¦Intentãæããï¼ã¨ããï¼ç»é¢æ§æãæ³å®ã
InputActivityå´ï¼
Intent intent = new Intent( InputActivity.this, ResultActivity.class ); // Parcelableã«intå¤ãã»ãã IntentData intentData = new IntentData(); intentData.setMyIntValue(99); // Intentã«Parcelableãã»ãã intent.putExtra("testParcelable", intentData); startActivity(intent);
ResultActivityå´ï¼
// IntentããParcelableãåãåºã Bundle extras = getIntent().getExtras(); IntentData intentData = (IntentData) extras.getParcelable("testParcelable"); Toast.makeText( this, // Parcelableããintå¤ãåãåºã "mData = " + intentData.getMyIntValue(), Toast.LENGTH_LONG ).show();
ParcelableãªIntentDataã¯ã©ã¹ï¼
package com.example; import android.os.Parcel; import android.os.Parcelable; /** * Intentã«ä»»æã®ãªãã¸ã§ã¯ããéæ¬ãããããã®å ¥ãç©ã * */ public class IntentData implements Parcelable { // éæ¬ããããã¼ã¿ private int mData; /** * 空ã£ã½ã®ç¶æ ã§ã¤ã³ã¹ã¿ã³ã¹ä½æ */ public IntentData() { // TODO èªåçæãããã³ã³ã¹ãã©ã¯ã¿ã¼ã»ã¹ã¿ã } /** * Parcelåäºå®ã®å¤ãset */ public void setMyIntValue(int i) { mData = i; } /** * Parcelåãããå¤ãget */ public int getMyIntValue() { return mData; } // ----- Parcelableã¤ã³ã¿ãã§ã¼ã¹ãå©ç¨ ãããã ----- /** * ãã¼ã¿ã®Parcelåãå®è¡ãã */ @Override public void writeToParcel(Parcel out, int flags) { out.writeInt( mData ); } /** * Parcelãããã¼ã¿ãèªã¿åºãprivateã³ã³ã¹ãã©ã¯ã¿ */ private IntentData(Parcel in) { mData = in.readInt(); } /** * Parcelãããã®Parcelableã®ã¤ã³ã¹ã¿ã³ã¹ãä½ãããã®Creator */ public static final Parcelable.Creator<IntentData> CREATOR = new Parcelable.Creator<IntentData>() { public IntentData createFromParcel(Parcel in) { return new IntentData(in); } public IntentData[] newArray(int size) { return new IntentData[size]; } }; /** * ã·ãªã¢ã©ã¤ãºããããªãã¸ã§ã¯ãã®ç¨®é¡ãå¤å¥ããããã®ããããã¹ã¯ãè¿ã */ @Override public int describeContents() { return 0; } // ----- Parcelableã¤ã³ã¿ãã§ã¼ã¹ãå©ç¨ ããã¾ã§ ----- }
ä¸è¨ã®ã³ã¼ããåä½ãããã¨ï¼ResultActivityå´ã§ãã¼ã¹ããåºã¦ã99ãã¨è¡¨ç¤ºãããã
Parcelableçµç±ã§ï¼æ£å¸¸ã«intå¤ãéæ¬ã§ãã¦ããã
æåã¯APIã®æå³ãææ¡ãã¥ããã
ã¾ã¨ããã¨ï¼ä¸è¨ã®ãããªäºæ ã
- Serializeï¼ç´ååï¼ããããã¼ã¿å½¢å¼ã®Androidç¹åçã¨ãè¨ãã¹ãï¼Parcelã¨ããå½¢å¼ï¼ã¯ã©ã¹ï¼ãåå¨ããã
- Serializableã®Androidç¹åçã¨ãè¨ãã¹ãï¼Parcelableãªã¯ã©ã¹ï¼ã¤ã³ã¿ãã§ã¼ã¹ï¼ãåå¨ããã
- Parcelableãªã¯ã©ã¹ã¯ï¼ä¸ç¨®ã®Streamæä½ã«ããï¼ä¿æãã¦ãããã¼ã¿ãParcelåããã
ï¼ï¼ï¼éParcelableãªãã¸ã§ã¯ããï¼Parcelableãªãã¸ã§ã¯ãã«æ ¼ç´ããã¨ã©ããªãã
intã®ãããªããªããã£ãå¤ã ãã§ãªãï¼ç¬èªã®ãªãã¸ã§ã¯ããParcelableå ã«æ ¼ç´ã§ããã®ãã
ä¸è¨ã§æ¤è¨¼ããã
ã¾ãï¼éæ¬ãããç¬èªãªãã¸ã§ã¯ããä½ãã
package com.example; /** * Parcelableçµç±ã§éæ¬å®é¨ããããã®é©å½ãªãªãã¸ã§ã¯ã */ public class Hoge { public int i; public String str; }
InputActivityå´ï¼
Intent intent = new Intent( InputActivity.this, ResultActivity.class ); // Hogeãªãã¸ã§ã¯ããçæãã¦è²ã ã»ãã Hoge hoge = new Hoge(); hoge.i = 77; hoge.str = "abc"; // Parcelableã«Hogeãªãã¸ã§ã¯ããã»ãã IntentData intentData = new IntentData(); intentData.setHogeObject( hoge ); // Intentã«Parcelableãã»ãã intent.putExtra("testParcelable", intentData); startActivity(intent);
ResultActivityå´ï¼
// IntentããParcelableãåãåºã Bundle extras = getIntent().getExtras(); IntentData intentData = (IntentData) extras.getParcelable("testParcelable"); // ParcelableããHogeãåãåºã Hoge hoge = intentData.getHogeObject(); Toast.makeText( this, // Hogeããå¤ãåãåºã "i = " + hoge.i + ", str = " + hoge.str, Toast.LENGTH_LONG ).show();
èå¿ãªParcelableï¼
package com.example; import android.os.Parcel; import android.os.Parcelable; /** * Intentã«ä»»æã®ãªãã¸ã§ã¯ããéæ¬ãããããã®å ¥ãç©ã * */ public class IntentData implements Parcelable { // éæ¬ããããã¼ã¿ private Object[] mData = new Object[1]; /** * 空ã£ã½ã®ç¶æ ã§ã¤ã³ã¹ã¿ã³ã¹ä½æ */ public IntentData() { // TODO èªåçæãããã³ã³ã¹ãã©ã¯ã¿ã¼ã»ã¹ã¿ã } /** * Parcelåäºå®ã®å¤ãset */ public void setHogeObject(Hoge hoge) { mData[0] = hoge; } /** * Parcelåãããå¤ãget */ public Hoge getHogeObject() { return (Hoge) mData[0]; } // ----- Parcelableã¤ã³ã¿ãã§ã¼ã¹ãå©ç¨ ãããã ----- /** * ãã¼ã¿ã®Parcelåãå®è¡ãã */ @Override public void writeToParcel(Parcel out, int flags) { out.writeArray( mData ); } /** * Parcelãããã¼ã¿ãèªã¿åºãprivateã³ã³ã¹ãã©ã¯ã¿ */ private IntentData(Parcel in) { mData = in.readArray( Hoge.class.getClassLoader() ); } /** * Parcelãããã®Parcelableã®ã¤ã³ã¹ã¿ã³ã¹ãä½ãããã®Creator */ public static final Parcelable.Creator<IntentData> CREATOR = new Parcelable.Creator<IntentData>() { public IntentData createFromParcel(Parcel in) { return new IntentData(in); } public IntentData[] newArray(int size) { return new IntentData[size]; } }; /** * ã·ãªã¢ã©ã¤ãºããããªãã¸ã§ã¯ãã®ç¨®é¡ãå¤å¥ããããã®ããããã¹ã¯ãè¿ã */ @Override public int describeContents() { return 0; } // ----- Parcelableã¤ã³ã¿ãã§ã¼ã¹ãå©ç¨ ããã¾ã§ ----- }
Parcelã«ã¯readObject()ã¨ãwriteObject()ã®ãããªã¡ã½ããã¯ãªãã
ãªã®ã§ï¼Object[]ãæ±ããreadArray()ã¨writeArray()ã使ã£ã¦ããã
ãããå®è¡ããã¨ï¼ä¸è¨ã®ãããªä¾å¤ã«ãªãã
ERROR/AndroidRuntime(6278): FATAL EXCEPTION: main ERROR/AndroidRuntime(6278): java.lang.RuntimeException: Parcel: unable to marshal value com.example.Hoge@40541288 ERROR/AndroidRuntime(6278): at android.os.Parcel.writeValue(Parcel.java:1132) ERROR/AndroidRuntime(6278): at android.os.Parcel.writeArray(Parcel.java:538) ERROR/AndroidRuntime(6278): at com.example.IntentData.writeToParcel(IntentData.java:49) ERROR/AndroidRuntime(6278): at android.os.Parcel.writeParcelable(Parcel.java:1151) ERROR/AndroidRuntime(6278): at android.os.Parcel.writeValue(Parcel.java:1070) ERROR/AndroidRuntime(6278): at android.os.Parcel.writeMapInternal(Parcel.java:488) ERROR/AndroidRuntime(6278): at android.os.Bundle.writeToParcel(Bundle.java:1552) ERROR/AndroidRuntime(6278): at android.os.Parcel.writeBundle(Parcel.java:502) ERROR/AndroidRuntime(6278): at android.content.Intent.writeToParcel(Intent.java:5476) ERROR/AndroidRuntime(6278): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1561) ERROR/AndroidRuntime(6278): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374) ERROR/AndroidRuntime(6278): at android.app.Activity.startActivityForResult(Activity.java:2827) ERROR/AndroidRuntime(6278): at android.app.Activity.startActivity(Activity.java:2933) ERROR/AndroidRuntime(6278): at com.example.InputActivity$1.onClick(InputActivity.java:42) ERROR/AndroidRuntime(6278): at android.view.View.performClick(View.java:2498) ERROR/AndroidRuntime(6278): at android.view.View$PerformClick.run(View.java:9129) ERROR/AndroidRuntime(6278): at android.os.Handler.handleCallback(Handler.java:587) ERROR/AndroidRuntime(6278): at android.os.Handler.dispatchMessage(Handler.java:92) ERROR/AndroidRuntime(6278): at android.os.Looper.loop(Looper.java:123) ERROR/AndroidRuntime(6278): at android.app.ActivityThread.main(ActivityThread.java:3728) ERROR/AndroidRuntime(6278): at java.lang.reflect.Method.invokeNative(Native Method) ERROR/AndroidRuntime(6278): at java.lang.reflect.Method.invoke(Method.java:507) ERROR/AndroidRuntime(6278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864) ERROR/AndroidRuntime(6278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622) ERROR/AndroidRuntime(6278): at dalvik.system.NativeStart.main(Native Method)
ãParcel: unable to marshal value com.example.Hogeãã¨ããã®ã§ï¼
æ示çã«ParcelableãªããSerializableæå®ãã¦ããªãHogeã¯ã©ã¹ã¯ï¼ç´ååã§ããªãã£ãã¨ããäºã ã
ï¼â»marshallã¨ã¯ãã³ãã»ç´ååã¿ãããªæå³ï¼
ãã¨ãParcelableãªã¯ã©ã¹ï¼IntentDataï¼ã®ä¸ã«æ ¼ç´ãã¦ãï¼ããã¾ã§é¢åã¯è¦ã¦ãããªãã
åèï¼
androidã¨ã©ã¼ãUncaught handler: thread main exiting due to uncaught exception,java.lang.RuntimeException: Parcel: unable to marshal value~ã
http://www.techmaru.net/wordpress/201...
- List使ç¨æã¯ï¼Listã®Tåãã·ãªã¢ã©ã¤ãºåããªããã°ãªããªã
- èªä½ListViewã®ãã¼ã¿ã¯ã©ã¹HogeListDataã¯Serializableã¤ã³ã¿ãã§ã¼ã¹ãå®è£ ãã¦ããªãã£ãã®ã§ãSerializableãå®è£ ãã¦ã¿ãããä¾å¤ãã§ãªããªã£ã
Exception: Parcel: Unable to marshal value?
https://groups.google.com/group/andro...
- ImageButtonã¯Serializableã§ããï¼ã¨ãã質åã«å¯¾ãï¼ãããã¥ã¢ã«ãèªãã°ï¼ç§ã§ãããäºãã»ã»ã»ãã¨ããããåçãã¤ãã¦ããæ§å
Parcelableã«é¢ããçµè«ã¨ãã¦ï¼
- Parcelableã«ãããç©ã®ä¸èº«ã¯ï¼å ¨é¨Parcelableã§ãªããã°ãªããªãã
å²ã¨å½ç¶ã®çµè«ã ãâ¦ã
â»Serializableããèªåã®ä¸ã§ç¶æ ãéãã¦ãããã¨ããè¦æ±ããã®ã§ï¼å¾åºAPIã§ããParcelableã«ã¯ï¼ããã¡ãã£ã¨è¦ªåãªæ¯ãèããæå¾ ãã¦ããã
大ä½äºæãã¦ããäºã ãã©ãï¼ããã¯ä½æ¥ã¨ãã¦ã¯ããã©ãã
ã·ãªã¢ã©ã¤ãºå¦çã®å 容ãï¼æ¯åï¼èªåã§ã³ã¼ãã£ã³ã°ããå¿ è¦ãããããã ã
Intentçµç±ã§ããããã®ãªãã¸ã§ã¯ããããåããããå ´åï¼
ãã¡ãã¡ã«Parcelable対å¿ã®ã³ã¼ããåãè¾¼ã¾ãªãã¨ï¼
ç¬èªãªãã¸ã§ã¯ãã®Intentåã渡ãã¯ä¸å¯è½ãï¼Javaãªã®ã§mix-inã§ããªãããï¼
ããä»®ã«CustomParcelableã¿ãããªåºåºã¯ã©ã¹ãä½ã£ã¦ç¶æ¿ããã¦ãï¼å ±éåã§ããã³ã¼ãã®éã«ã¯éçãããã
ã§ã¯ã©ããããã
ï¼ï¼ï¼ã·ã³ãã«ãªSerializableãæãç¡é£ã
Parcelableã使ããã¨ããå ã ã®çç±ã¯ï¼
- Serializableã®å ´åã¨æ¯è¼ããã¨å¿ç¨ãå¹ãï¼ã¢ããªå¤ã¸ã®æé»çIntentã«ãå©ç¨ã§ããããã
ã¨ããäºã ã£ãã
ãããï¼ããã¯ãã¢ããªéé£æºããæèããã¨ããäºã
ã¾ãã¯ï¼ã¢ããªã®å¤é¨ãã©ãã®ããã®ã¨ããå¿ç¨çãªã´ã¼ã«ã¯èã«ç½®ãã¨ããã
ããã¦ãIntentã«ç¬èªãªãã¸ã§ã¯ããéæ¬ãããããã¨ããï¼æ¬æ¥ã®ã´ã¼ã«ãæãåºããã
ããã§ããã°ï¼Serializableã§ååã
InputActivityå´ï¼
Intent intent = new Intent( InputActivity.this, ResultActivity.class ); // Hogeãªãã¸ã§ã¯ããçæ Hoge hoge = new Hoge(); hoge.i = 77; hoge.str = "abc"; // Intentã«Hogeãã»ãã intent.putExtra("testSerializable", hoge); startActivity(intent);
ResultActivityå´ï¼
// IntentããHogeãåãåºã Bundle extras = getIntent().getExtras(); Hoge hoge = (Hoge) extras.getSerializable("testSerializable"); Toast.makeText( this, // Hogeããå¤ãåãåºã "i = " + hoge.i + ", str = " + hoge.str, Toast.LENGTH_LONG ).show();
SerializableãªHogeï¼
package com.example; import java.io.Serializable; /** * Intentçµç±ã§éæ¬ãããããã®é©å½ãªãªãã¸ã§ã¯ã */ public class Hoge implements Serializable { private static final long serialVersionUID = 1L; // ã¡ã¤ã³ã®å±æ§ public int i; public String str; }
ååã¾ã§ãã£ãIntentDataã¨ããã¯ã©ã¹ã¯ï¼ãã使ããªãã
ããã§ããã¸ã§ã¯ããå®è¡ããã¨ï¼ç»é¢é·ç§»æã«ã¯ãi = 77, str = abcãã¨ããToastãç¡äºï¼ç¾ãã¦ãããã
Hogeãªãã¸ã§ã¯ããï¼Intentçµç±ã§ç¡äºï¼éæ¬ã§ãã¦ããã
Parcelableãå©ç¨ããå ´åã«æ¯ã¹ã¦ï¼ã¯ããã«ã·ã³ãã«ã ã
éæ¬å¯¾è±¡ã®Hogeã¯ã©ã¹ã«å¯¾ãã¦ä»ä¸ãã¹ãã³ã¼ãçã¯ï¼ãã£ãã®ï¼ãæã
é常ã®ç´ååå¯è½ã¯ã©ã¹ã®ä½ææã¨åãããã«ï¼ implements Serializable ãã¦ï¼ã·ãªã¢ã«IDããã£ã¤ããã ãã
éæ¬å¯¾è±¡ãå½¢å¼å¤æããããã®ç¹å¥ãªå¤é¨ã¯ã©ã¹ãä½ããªãã¦æ¸ãã
ã¨ã¯ããï¼ãã¡ãããã®å ´åã¯ï¼Javaããã°ã©ãã³ã°ã«ãããSerializableã®ç¨æ³ã®ä¸è¬è«ãå½ã¦ã¯ã¾ããã¨ã«ãªãã
ç´ååå¯è½ã«ããããªãã¸ã§ã¯ãã¯ï¼èªåèªèº«ã®ä¸ã§ç¶æ ããéãã¦ãããªããã°ãªããªãã
Effective Java 第ï¼çã®11ç« ãã·ãªã¢ã©ã¤ãºãã®å 容ãèªã¿è¿ãã¨ãããé ç®17ãåèã«ãªãã
ããªãã¸ã§ã¯ããä¸æ¦ã·ãªã¢ã©ã¤ãºãããã¨ï¼ãã®ç¬¦å·åããããã®ã¯ï¼å®è¡ä¸ã®ä»®æ³ãã·ã³ããä»ã®ä»®æ³ãã·ã³ã¸éä¿¡ã§ãã¾ãâ¦ã·ãªã¢ã©ã¤ãºã«ã¯ããã°ã©ãã®å´ã§ä½ãåªåãè¦ããªãã¨ããåºãç¥ããã誤解ãããã¾ããâ¦
ãªãã¸ã§ã¯ãã®è»¢éãæ°¸ç¶åã«é¢ãã¦ã·ãªã¢ã©ã¤ãºã«ä¾åããä½ããã®ãã¬ã¼ã ã¯ã¼ã¯ã§ã¯ã©ã¹ã使ç¨ãããã®ã§ããã°ï¼ï¼Serializableã¤ã³ã¿ãã§ã¼ã¹ãï¼å®è£ ããã®ã¯åºæ¬çãªãã¨ã§ããâ¦
æ´»åçãªå®ä½ã表ãã¯ã©ã¹ã¯ï¼Serializableããã£ãã«å®è£ ãã¹ãã§ã¯ããã¾ãããâ¦
ç¶æ¿ã®ããã«è¨è¨ãããã¯ã©ã¹ã¯Serializableããã£ãã«å®è£ ãã¹ãã§ã¯ããã¾ããâ¦ãã®è¦åãç ´ãã®ãé©åãªæãããã¾ããâ¦
ï¼ãã·ãªã¢ã©ã¤ãºæã®çç¾ãåé¡ã«ãªããªãéãï¼serialVersionUIDã«ã©ã®ãããªå¤ãé¸ãã§ãåé¡ã¯ããã¾ããã
ã
"Effective Java", 11ç« ï¼2010.
Androidã¢ããªã®å®è¡ã¢ãã«ã¯ï¼ã¢ããªæ¯ã«ããã»ã¹ãDalvik VMãåããã¦ããäºãæãåºããã
ã¾ãï¼ããã§ã¯ãã¢ããªéé£æºãã®å¯è½æ§ãé¤å¤ãã¦ããã®ã§ï¼ãã·ãªã¢ã©ã¤ãºæã®çç¾ãçºçããªãäºã«æ³¨æãããã
åèURLï¼
Effective Java èªæ¸ä¼ 14 æ¥ç® ãã·ãªã¢ã©ã¤ãºï¼ã·ãªã¢ã©ã¤ãºï¼ã(by amachang)
http://d.hatena.ne.jp/amachang/201003...
ã·ãªã¢ã©ã¤ãºããå ´åããªãSerializableã¤ã³ã¿ã¼ãã§ã¼ã¹ãè¼ããªããã°ãªããªãä»æ§ãªã®ãï¼ãserialVersionUIDã®å½¹å²ã¯ä½ãï¼
http://okwave.jp/qa/q3997360.html#besta
- Sun JavaVMã¯å é¨çã«if(hoge instanceOf Serializable)ã®ãã§ãã¯ãè¡ã£ã¦ãã
- ãã¡ã¤ã«ãªãã¸ã§ã¯ãã®ã¤ã³ã¹ã¿ã³ã¹ãä¿æ(has-A)ãããããªã¯ã©ã¹ã¯ã·ãªã¢ã©ã¤ãºã§ãã¾ãããã»ã»ã»ãã·ãªã¢ã©ã¤ãºä¸å¯è½ãã¨ã¯ï¼ç¶æ ãèªåã®ä¸ã§éãã¦ããªãã¨ããäº
ï¼ï¼ï¼ã¤ã³ãã¼ã¯ã©ã¹ãSerializableã«ãããæã®è©¦ç·´
ãããªããã§ï¼ç¡é£ãªSerializableã使ãã°ï¼å¤§ä½æããã®ã¯ä½ã§ãIntentã«æ ¼ç´ã§ãããªãã¨å®å¿ããããã
ã¨ãããããã«ç½ ãããã
ã¤ã³ãã¼ã¯ã©ã¹ãå¿åã¯ã©ã¹ã¯ï¼ç°¡åã«ã¯ã·ãªã¢ã©ã¤ãºã§ããªãã®ã§ããã
ä¾ãã°ï¼ä¸è¨ã®ã½ã¼ã¹ãè¦ã¦ã»ããã
Android-MVCãã¬ã¼ã ã¯ã¼ã¯ ver0.1 ã®ï¼ãã¸ãã¹ãã¸ãã¯ã®ãµã³ãã«
http://code.google.com/p/android-mvc-...
ã¡ã½ããã®æ»ãå¤é¨åã¯ï¼ä¸è¨ã®ããã«ãªã£ã¦ããã
ã»ã»ã» // å®è¡çµæãè¿ã return new ActionResult(){ @Override public void onNextActivityStarted(final Activity activity) { activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText( activity, get("new_friend_name") + "ãããç»é²ãã¾ããã", Toast.LENGTH_LONG ).show(); } }); } } .setRouteId("success") .add("new_friend_name", f.getName()) ;
ãã®ã³ã¼ãã£ã³ã°ã¹ã¿ã¤ã«ã¯ï¼èªç¶ãªæèã®æµãã«æ²¿ã£ããã®ã ã
ãä½ããè¿å´ãããããã«returnã¨æ¸ãã¦ããï¼æ»ãå¤ãªãã¸ã§ã¯ããå¿åã¯ã©ã¹ã®å½¢ã§å®ç¾©ãå§ããã
ãªã®ã§ï¼
- returnããå¾ã®é¨åã¯å ¨é¨ï¼ã¡ã½ããã®è¿å´å¤ã¨ãã¦å©ç¨ããããã¨ãä¸ç®çç¶ã«åããã
- ãã®ãªãã¸ã§ã¯ããå¤æ°ã«ä¿æãããããªåé·ããä¸è¦ã«ãªã£ã¦ããã
- ã½ã¼ã¹ã³ã¼ãã®å¦çå ¨ä½ã®æµããã¡ã½ãããã§ã¤ã³ã§é çªã«è¨è¿°ãããã®ã§ï¼ææ¡ããããã
æµãããããªã³ã¼ãã£ã³ã°ã¹ã¿ã¤ã«ãå®ç¾ããããã«ï¼å¿åã¯ã©ã¹ãä¸å½¹è²·ã£ã¦ããã®ã ã
ã ããããï¼ããã§å¿åã¯ã©ã¹ã¨ãã¦å©ç¨ãã¦ããActionResultãï¼
Intentã§éæ¬ããããã«Serializableã«ããã¨ï¼åé¡ãèµ·ããã
ã¾ãï¼å¥ãã¡ã¤ã«ã«ã¦ActionResultã®å®ç¾©ã«ãimplements Serializableããï¼serialVersionUIDãã»ããããã
ããã¨ï¼ä¸è¨ã®å¿åã¯ã©ã¹å©ç¨å´ã®ã½ã¼ã¹ã«ããã¦ãï¼
ãreturn new ActionResult(){ãã®æ¬¡ã®è¡ã«serialVersionUIDãã»ããããããã«è¦åãåºãã
ããã§å¤§ä¸å¤«ãã¨æãï¼Intentã«putExtra()ãã¦ã·ãªã¢ã©ã¤ãºã試ã¿ãã¨ã»ã»ã»
ERROR/AndroidRuntime(31477): FATAL EXCEPTION: AsyncTask #5 ã»ã»ã» ERROR/AndroidRuntime(31477): Caused by: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.android_mvc.sample_project.domain.DBEditAction$1) ERROR/AndroidRuntime(31477): at android.os.Parcel.writeSerializable(Parcel.java:1176) ERROR/AndroidRuntime(31477): at android.os.Parcel.writeValue(Parcel.java:1130) ERROR/AndroidRuntime(31477): at android.os.Parcel.writeMapInternal(Parcel.java:488) ERROR/AndroidRuntime(31477): at android.os.Bundle.writeToParcel(Bundle.java:1552) ERROR/AndroidRuntime(31477): at android.os.Parcel.writeBundle(Parcel.java:502) ERROR/AndroidRuntime(31477): at android.content.Intent.writeToParcel(Intent.java:5476) ERROR/AndroidRuntime(31477): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1561) ERROR/AndroidRuntime(31477): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374) ERROR/AndroidRuntime(31477): at android.app.Activity.startActivityForResult(Activity.java:2827) ERROR/AndroidRuntime(31477): at android.app.Activity.startActivity(Activity.java:2933) ERROR/AndroidRuntime(31477): at com.android_mvc.framework.controller.routing.Router.switchByActionResult(Router.java:109) ERROR/AndroidRuntime(31477): at com.android_mvc.framework.controller.ControlFlowDetail$3.main(ControlFlowDetail.java:165) ERROR/AndroidRuntime(31477): at com.android_mvc.framework.task.SequentialAsyncTask.doInBackground(SequentialAsyncTask.java:102) ERROR/AndroidRuntime(31477): at com.android_mvc.framework.task.SequentialAsyncTask.doInBackground(SequentialAsyncTask.java:1) ERROR/AndroidRuntime(31477): at android.os.AsyncTask$2.call(AsyncTask.java:185) ERROR/AndroidRuntime(31477): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) ERROR/AndroidRuntime(31477): ... 4 more ERROR/AndroidRuntime(31477): Caused by: java.io.NotSerializableException: com.android_mvc.sample_project.domain.DBEditAction ERROR/AndroidRuntime(31477): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1535) ERROR/AndroidRuntime(31477): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847) ERROR/AndroidRuntime(31477): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689) ERROR/AndroidRuntime(31477): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653) ERROR/AndroidRuntime(31477): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1143) ERROR/AndroidRuntime(31477): at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:413) ERROR/AndroidRuntime(31477): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1241) ERROR/AndroidRuntime(31477): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575) ERROR/AndroidRuntime(31477): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847) ERROR/AndroidRuntime(31477): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689) ERROR/AndroidRuntime(31477): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653) ERROR/AndroidRuntime(31477): at android.os.Parcel.writeSerializable(Parcel.java:1171) ERROR/AndroidRuntime(31477): ... 19 more
ã¨ãã風ã«ï¼ã¤ã³ãã¼ã¯ã©ã¹ãå²ã£ã¦ããå¤å´ã®ã¯ã©ã¹ï¼ï¼ã¨ã³ã¯ãã¼ã¸ã³ã°ã»ã¤ã³ã¹ã¿ã³ã¹ï¼ã«å¯¾ãã¦ãjava.io.NotSerializableExceptionãã¨ãªãã
ã§ï¼LogCatã®æ示ã«å¾ã£ã¦ï¼ã¢ã¦ã¿ã¼ã¯ã©ã¹ã§ããDBEditActionãSerializableã«ãã¦ã¿ãã¨ï¼ä»åº¦ã¯åãã¨ã©ã¼ã¡ãã»ã¼ã¸ã
java.io.NotSerializableException: com.android_mvc.sample_project.activities.func_db.DBEditActivity
ã®ããã«ï¼ãªãã¸ã§ã¯ãã®åç §ãã¤ãã£ã¦èã¥ãå¼ã«åºãã£ã¦ããã
ãããªã¨ã©ã¼ã¡ãã»ã¼ã¸ã®è¨ãäºãåé¢éãåãåã£ã¦ï¼ç²ç®çã«å¾ã£ã¦ãããï¼ãã¾ãã«ã¯å ¨é¨ã®ãªãã¸ã§ã¯ããSerializableã«ããå¿ è¦ãçãã¦ãã¾ãã
ãªã®ã§ï¼ä¸åº¦åºæ¬ã«ç«ã¡è¿ãå¿ è¦ãããã
Javaè¨èªã®ææ³ä»æ§ã§ã¯ï¼ã¤ã³ãã¼ã¯ã©ã¹ã¨ã¯ã©ãããä½ç½®ã¥ãã«ããã®ãã
ã¤ã³ãã¼ã¯ã©ã¹ã®Serializeã¨ããè¡çºèªä½ã«ï¼åé¡ãããã®ãã
ã¤ã³ãã¼ã¯ã©ã¹ãã·ãªã¢ã©ã¤ãºåºæ¥ã Sep. 14, 1998
http://www2s.biglobe.ne.jp/~dat/java/...
- ã¤ã³ãã¼ã¯ã©ã¹ã®ã·ãªã¢ã©ã¤ãºã«å¤±æãã¦ããã®ã¯ãã¢ã¦ã¿ã¼ã¯ã©ã¹ ã Serializable ã implements ãã¦ããªãããã§ã¯ï¼
classã¨static classã¨ã§ã¯ã親ã®åç §ã®æã¡æ¹ãéã
http://blog.xole.net/article.php?id=585
- staticãä»ããªããclassãã§å®£è¨ããã¨ï¼è¦ªã®åç §ãæã¤ãã¨ã«ãªã
- ãµã³ãã«ã§ã¯ãSerializableãå®è£ ãã¦ãããªãã¸ã§ã¯ãã®ãã¤ãæ°ãåå¾ãããã¨ãã¦ãã¾ãããï¼staticãä»ããªãï¼é常ã®classã§å é¨ã¯ã©ã¹ãå®è£ ãããããè¡ããã¨ããã¨ã親ã¯ã©ã¹å´ã«ã¤ãã¦ä¾å¤ãçºçãã¦ãã¾ããå é¨ã¯ã©ã¹ã®Hogeã¯è¦ªã¯ã©ã¹(InnerClassSample)ã®åç §ãæã£ã¦ããããã試ãã«ã親ã¯ã©ã¹ã§Serializableãå®è£ ãããã¨ã§ãã¡ã½ããtestã®å®è¡ã¯å¯è½ã¨ãªã
- static classã§å é¨ã¯ã©ã¹ãå®è£ ããå ´åã¯ä¾å¤ãçºçãã¾ãã
Unable to serialize anonymous classes.ï¼Oracleã®å ¬å¼ãã¼ã¸ï¼å¿åã¯ã©ã¹ãã·ãªã¢ã©ã¤ãºã§ããªãã®ã¯ãã°ãã¨ãã質åï¼
http://bugs.sun.com/bugdatabase/view_...
Because inner classes declared in non-static contexts
contain implicit non-transient references to enclosing class
instances, serializing such an inner class instance will result in
serialization of its associated outer class instance as well.訳ï¼
staticã§ãªãã³ã³ããã¹ãä¸ã§å®£è¨ãããã¤ã³ãã¼ã¯ã©ã¹ã¯ï¼ã¨ã³ã¯ãã¼ã¸ã³ã°ã»ã¤ã³ã¹ã¿ã³ã¹ã«å¯¾ããæé»ã®étransientã®åç §ãæã¡ã¾ãã
ï¼â»transientã¯ã·ãªã¢ã©ã¤ãºã®å¯¾è±¡å¤ã«ããããã®æ¼ç®åãétransientã¨ã¯ï¼ã·ãªã¢ã©ã¤ãºã®å¯¾è±¡ããéããããªãã¨ãããã¨ï¼
ãã®ããï¼ãã®ãããªã¤ã³ãã¼ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ãã·ãªã¢ã©ã¤ãºãããã¨ããã¨ï¼ããã¨é¢é£ãæã¤ã¢ã¦ã¿ã¼ã¯ã©ã¹ãåæ§ã«ç´ååå¦çã®å¯¾è±¡ã«ãªãã¾ãã
â»å ¨ãåãäºãï¼Javaè¨èªä»æ§ã®
1.10 The Serializable Interfaceã®NOTEã«æ¸ããã¦ããã
http://docs.oracle.com/javase/7/docs/...
SER05-J. Do not serialize instances of inner classes
https://www.securecoding.cert.org/con...
- Risk Assessment : Serialization of inner classes can introduce platform dependencies and can cause serialization of instances of the outer class.
- ã³ã³ãã¤ã©ã®å®è£ ä¾åã§ã·ãªã¢ã©ã¤ãºå¯¾è±¡ç¯å²ã®æåãå¤ãã£ã¦ãã¾ãå¯è½æ§ãããããï¼ã¤ã³ãã¼ã¯ã©ã¹ã®ç´ååãã®ãã®ããªã¹ã¯ã§ãã
Effective Javaã®p284ã«ãï¼ä¸è¨ã®ãããªæ³¨ææ¸ããããã
ã
å é¨ã¯ã©ã¹ã¯ï¼Serializableãå®è£ ãã¹ãã§ã¯ããã¾ãããå é¨ã¯ã©ã¹ã¯ï¼ã¨ã³ã¯ãã¼ã¸ã³ã°ã¤ã³ã¹ã¿ã³ã¹ã«å¯¾ããåç §ãä¿æããããâ¦ã³ã³ãã¤ã©çæã«ãã人工çãã£ã¼ã«ãï¼synthetic fieldï¼ã使ç¨ãã¦ãã¾ããâ¦
ãããã£ã¦ï¼å é¨ã¯ã©ã¹ã®ããã©ã«ãã®ã·ãªã¢ã©ã¤ãºå½¢å¼ã¯ï¼ä¸æ確ã§ãã
ãããï¼staticã®ã¡ã³ãã¼ã¯ã©ã¹ã¯ï¼Serializableãå®è£ ã§ãã¾ãã
ã
ã¾ã¨ããã¨ï¼ã¤ã³ãã¼ã¯ã©ã¹ãã·ãªã¢ã©ã¤ãºããããã«ã¯
- ã¤ã³ãã¼ã¯ã©ã¹ãstaticã³ã³ããã¹ãã§å®ç¾©ãããã¨
- ã¢ã¦ã¿ã¼ã¯ã©ã¹ãï¼é¢é£ããå ¨ã¦ã®ãªãã¸ã§ã¯ããSerializableã«ãããã¨
ã®ãããããè¦æ±ãããã
â»ãã®çç±ã¯ï¼ãã åã«Javaè¨èªã®ã³ã³ãã¤ã©ã®ä»æ§ã§ãããããã°ã©ãã®ä¾¿çãå³ã£ãä»æ§ã§ã¯ãªãããã®ãããã«Javaã®ãããããããã¼ã¯ãµã¤ããè¦ãé ãããã*1
ã§ã¯ããä¸æ©åå¿ã«æ»ã£ã¦ï¼Javaè¨èªã«ããã¦ï¼ã¤ã³ãã¼ã¯ã©ã¹ãstaticã«ãªãå ´åã®å¹ç¨ã¨ã¯ä½ã ã£ãã ãããã
[Java]ãªãã§staticãã¤ãã¦ãªãã¨ãã¡ãªã®ï¼
http://d.hatena.ne.jp/nowokay/20070125
- staticãã¤ãã¦ãªããã®ã使ã£ã¦ãã¨ãã«ã¯thisãçç¥ããã¦ã
- this.new B();
- new A().new B();
staticãªå é¨ã¯ã©ã¹ã¯å é¨ã¯ã©ã¹ããããªã
http://d.hatena.ne.jp/jyukutyo/200610...
- new OuterClass().new InnerClass(); ï¼éstaticãªï¼å é¨ã¯ã©ã¹ã®çæã«ã¯å¤é¨ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ãå¿ è¦
- InnerClassã«staticãã¤ãã¡ããã¨ãstaticãªã ãã«å¤é¨ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã«ã¢ã¯ã»ã¹ã§ããªããªããã ããstaticãªå é¨ã¯ã©ã¹ã¯å é¨ã¯ã©ã¹ã¨å¼ã¹ãªããªã£ã¡ãã
Inner Classã®staticæãã¨ç¡ãã®éã
http://d.hatena.ne.jp/quabbin/2008092...
- ã親ã¯ã©ã¹$åã¯ã©ã¹.classãã¨ãããããªãã¡ã¤ã«ï¼ãã¤ãã³ã¼ãï¼ãjavapã§éã¢ã»ã³ãã«ãã¦éãã観å¯
- static修飾ãããã¦ããªãã¨this$0ã®å®ç¾©ãèµ°ããåé¢ä¸ã¯åå¨ããªãå½¢ã§ããã©ã«ãã³ã³ã¹ãã©ã¯ã¿ã®å¼æ°ãä¸ã¤å¢ãã¦ãã
- static修飾ã®ãªãã¤ã³ãã¼ã¯ã©ã¹ã§ã¯ï¼enclosingã¢ã¯ã»ã¹ãã§ããããã«åæåããã³ã¹ããããã
ä¸è¨ãè¦ç´ããã«ï¼ã¤ã³ãã¼ã¯ã©ã¹ã®å®ç¾©ã«static修飾ãæ½ããã¦ããã°ï¼ã¢ã¦ã¿ã¼ã¯ã©ã¹ã¸ã®åç §ã¯é絶ãã¦ããããã¨è¨ãäºã«ãªãã
ããããããã§ï¼ãã®é ã®åé ã§åãä¸ãããµã³ãã«ã³ã¼ããåé¡ãªãSerializableã«ããããã«ã¯ï¼ä¸è¨ã®ãããªã³ã¼ããæ¸ãã°ããäºã«ãªãã
ã»ã»ã» // å®è¡çµæãè¿ã return new DBEDitActionResult() .setRouteId("success") .add("new_friend_name", f.getName()) ; } // å®è¡çµæãªãã¸ã§ã¯ãï¼â»staticå®ç¾©ããã¦ããç¹ã«æ³¨æï¼ static class DBEDitActionResult extends ActionResult { private static final long serialVersionUID = 1L; @Override public void onNextActivityStarted(final Activity activity) { ã»ã»ã» } }
ãã®ããã«ï¼å®ç¾©æ¹æ³ãå¤æ´ãã¦ï¼ActionResultãç¶æ¿ããstaticãªå é¨ã¯ã©ã¹ã¨ãã¦å®è£ ããã°ï¼ãã¤ã¦å¿åã¯ã©ã¹ã ã£ãã¢ãã¯ç¡äºã«Serializeã§ããã
ä¸è¨ã®DBEDitActionResultã¯ï¼åé¡ãªãIntentã§éæ¬å¯è½ã§ãããå®è¡æä¾å¤ã¯çºçããªãã
å®éï¼ä¸ã§åãä¸ãããAndroid-MVC frameworkãã®ver0.2ã§ã¯ï¼ãã®æ¹æ³ãæ¡ç¨ãããã
ãã®çµæï¼ä»»æã®ãªãã¸ã§ã¯ãã«å¯¾ãã¦ãimplements IntentPortableãããã ãã§ï¼è©²å½ãªãã¸ã§ã¯ããIntentçµç±ã§éæ¬å¯è½ã¨ãªã£ãã®ã§ããã
Androidã¢ããªéçºç¨ã®MVCãã¬ã¼ã ã¯ã¼ã¯ ãAndroid-MVCã ver0.2ããªãªã¼ã¹
http://language-and-engineering.hatenablog.jp/entry/20120323/p1
- ãâ ã¨ã³ãã£ãã£ãå«ãä»»æã®èªä½ãªãã¸ã§ã¯ããï¼Intentçµç±ã§æ°è»½ã«éæ¬å¯è½ã«ãªã£ãã ãã¨ããé ç®ãåç §ã
ã¨ã¯ããï¼ãã®ãããªJavaè¨èªã®ç¡ç¨ãªä»æ§ã«å¼·å¶çã«å¾ããããããããã§ï¼ã³ã¼ããåæãããããï¼å¯èªæ§ãæãªãããã¨ãããã¡ãªãããããã
å¿åã¯ã©ã¹ã®å½¢æ ãä¿æãããã¨ã¯ä¸å¯è½ã«ãªãã®ã ã
ActionResultã«ãã¼ã¿ãã»ããããé¨åã¨ï¼ã»ããããããã¼ã¿ãå©ç¨ããé¨åãï¼æãã»æã¾ãªããåããã«ï¼å¼·å¶çã«åæããã¦ãã¾ãã
ãã®é½åããåãå ¥ããã°ï¼ãã®ã³ã¼ãã¯ä¸å¿åãã
ãã ï¼çæ³çãªè¨è¨ãï¼çæ³çãªDSLã®æ§ç¯ã¯å¦¨ããããã
ãããJavaãã©ãããã©ã¼ã ã
æ¯è¼ã¨çµè«
ç¬èªãªãã¸ã§ã¯ããIntentã§éæ¬ãããå ´åï¼ä»¥ä¸ã®ï¼ã¤ã®æ¹æ³ãããã
Parcelable
- ã¡ãªããï¼Androidä¸ã§ã®ããã©ã¼ãã³ã¹ã«æé©åããã¦ãããã¢ããªéã®éä¿¡ã«ã使ããã
- ãã¡ãªããï¼ããã©ããã³ã¼ãéãå¤ãããã¼ã¿ã®åºãå ¥ããåé·ã
Serializable
- ã¡ãªããï¼ããããããªã³ã¼ãã®ä»å ã ãã§ï¼æ軽ã«å©ç¨ã§ãããä¸è¬ã®Javaã¯ã¼ã«ãã§æ®åãã¦ããAPIã§ãããã
- ãã¡ãªããï¼ã¢ããªå ã®æ示çã¤ã³ãã³ãã«éå®ããããå¿åã¯ã©ã¹ãã¤ã³ãã¼ã¯ã©ã¹ã¯static宣è¨ã§åãåããå¿ è¦ãããã
å©ç¨ç®çãè¸ã¾ããä¸ã§ï¼ããããã®æ¹æ³ãé¸ãã§ä½¿ãäºã«ãªãã
ãã¼ã«ãªãã®ã¯ï¼ä»ã¢ããªã¨ã®é£æºã®æç¡ã
å°è¦æ¨¡ã¢ããªã§ãã£ã¦ãï¼ç¬èªãªãã¸ã§ã¯ããå«ããããªæé»çã¤ã³ãã³ããæããã®ã§ããã°ï¼Parcelableã®å©ç¨ãå¿ é ã«ãªãã
ã³ã³ãã³ããªã¾ã«ããã³ã³ãã³ããããã¤ãã使ãã«ãããï¼AIDLãParcelableã«ããIPCãå¿ è¦ã ã
Android ã¤ã³ã¿ã¼ãã§ã¤ã¹å®ç¾©è¨èª ( AIDL ) / Parcelable ã使ç¨ãããã©ã¡ã¼ã¿å¤ã®åã渡ã
http://www.techdoctranslator.com/andr...
ä¸æ¹ï¼è¤éãªã¢ããªã§ãã£ã¦ãï¼å¤é¨ã«ã¤ã³ãã³ããæããªãã®ã§ããã°ï¼Serializableã§ååã
ããã¦ç¾ç¶ãè¨ãã¨ï¼ä»ã¢ããªã¨ã®é£æºæã«ã¯ï¼ãã¡ãã¡ç¬èªãªãã¸ã§ã¯ããå梱ããå¿ è¦ãªã©çããªãã®ãæ¬å½ã®ã¨ããã ã
Twitterã§ã·ã§ã¢ã¨ãï¼ç»åããã¥ã¼ã¯ã§é²è¦§ã¨ãï¼æåã©ããã®ã¢ããªé£æºã®æ¹æ³è«ã¯ãã§ã«ç¢ºç«ãã¦ããï¼ãããã®æ¹æ³ã¯æ¥µãã¦ã·ã³ãã«ã ã
ãªã®ã§ï¼ç¦ã£ã¦Parcelableã使ããã¨ããå¿ è¦ã¯ï¼ãã¾ããªãã®ãããããªãã
é¢é£ã¨ã³ããªï¼
éã³ã³ãã¤ã« ï¼ éã¢ã»ã³ãã« ã®ããã®ï¼ã¤ã®ç¡æãã¼ã«ï¼javapãå«ãï¼
http://language-and-engineering.hatenablog.jp/entry/20081008/1223384382
ã
*1:æ¸ç±ããããã¯ãã£ãã»ããã°ã©ãããªã©ãåç §ã