1. Android Studio 自动生成 serialVersionUID
http://stackoverflow.com/questions/12912287/intellij-idea-generating-serialversionuid
勾上就OK了!~File => Settings... => Inspections => Serialization issues => Serializable class without 'serialVersionUID'
找不到直接在Preference中直接搜索Serialization issues!直接Alt+enter直接就提示了!
2.关于EDITTEXT的一些小问题
输入回车不能自动换行
android:inputType="textMultiLine"//原本被我设置为text,导致不能输入多行。
//如果要限制为只允许一样,加android:singleLine="true" ,或者改为上面这个输入类型就好了
//或者设置android:maxHeight="60dp" 的形式
3.数据库的一些问题
因为使用混淆,用ormlite去操作的时候,可能类名被更改。
所以会导致找不到表的bug。这时候请注意看下你手机的数据库的表明
和你的查询语句有问题不一致的,特别是一些用用sql语句写的查询之类的。
("update record set planId = ? , userId = ? where planId = ?", planId, plan.getUserId(), plan.getPlanId());
这样的语句,在混淆后就难以保证正确性啦。
Caused by:
android.database.sqlite.SQLiteException: no such table: while compiling: ~~~~~~~~~~~~~~~~~~~~~~~~~
11-13 16:04:04.209: ERROR/AndroidRuntime(19827): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
Case 4 :当我们从一个Activity启动了一个Fragment,然后在这个Fragment中又去实例化了一些子Fragment,在子Fragment中去有返回的启动了另外一个Activity,即通过startActivityForResult方式去启动,这时候造成的现象会是,子Fragment接收不到OnActivityResult,如果在子Fragment中是以getActivity.startActivityForResult方式启动,那么只有Activity会接收到OnActivityResult,如果是以getParentFragment.startActivityForResult方式启动,那么只有父Fragment能接收(此时Activity也能接收),但无论如何子Fragment接收不到OnActivityResult。
这是一个非常奇怪的现象,按理说,应该是让子Fragment接收到OnActivityResult才对,究竟是什么造成的呢?这是由于某位写代码的员工抱怨没发奖金,稍稍偷懒了,少写了一部分代码,没有考虑到Fragment再去嵌套Fragment的情况。
我们来看看FragmentActivity中的代码:
<span class="kd"><span class="keyword" style="font-weight: bold;">protected</span></span> <span class="kt"><span class="keyword" style="font-weight: bold;">void</span></span> <span class="nf">onActivityResult</span><span class="o">(</span><span class="kt"><span class="keyword" style="font-weight: bold;">int</span></span> <span class="n">requestCode</span><span class="o">,</span> <span class="kt"><span class="keyword" style="font-weight: bold;">int</span></span> <span class="n">resultCode</span><span class="o">,</span> <span class="n">Intent</span> <span class="n">data</span><span class="o">)</span> <span class="o">{</span> <span class="k"><span class="keyword" style="font-weight: bold;">this</span></span><span class="o">.</span><span class="na">mFragments</span><span class="o">.</span><span class="na">noteStateNotSaved</span><span class="o">();</span> <span class="kt"><span class="keyword" style="font-weight: bold;">int</span></span> <span class="n">index</span> <span class="o">=</span> <span class="n">requestCode</span> <span class="o">>></span> <span class="mi"><span class="number" style="color: rgb(0, 153, 153);">16</span></span><span class="o">;</span> <span class="k"><span class="keyword" style="font-weight: bold;">if</span></span> <span class="o">(</span><span class="n">index</span> <span class="o">!=</span> <span class="mi"><span class="number" style="color: rgb(0, 153, 153);">0</span></span><span class="o">)</span> <span class="o">{</span> <span class="n">index</span><span class="o">--;</span> <span class="k"><span class="keyword" style="font-weight: bold;">if</span></span> <span class="o">((</span><span class="k"><span class="keyword" style="font-weight: bold;">this</span></span><span class="o">.</span><span class="na">mFragments</span><span class="o">.</span><span class="na">mActive</span> <span class="o">==</span> <span class="kc"><span class="keyword" style="font-weight: bold;">null</span></span><span class="o">)</span> <span class="o">||</span> <span class="o">(</span><span class="n">index</span> <span class="o"><</span> <span class="mi"><span class="number" style="color: rgb(0, 153, 153);">0</span></span><span class="o">)</span> <span class="o">||</span> <span class="o">(</span><span class="n">index</span> <span class="o">>=</span> <span class="k"><span class="keyword" style="font-weight: bold;">this</span></span><span class="o">.</span><span class="na">mFragments</span><span class="o">.</span><span class="na">mActive</span><span class="o">.</span><span class="na">size</span><span class="o">()))</span> <span class="o">{</span> <span class="n">Log</span><span class="o">.</span><span class="na">w</span><span class="o">(</span><span class="s"><span class="string" style="color: rgb(221, 17, 68);">"FragmentActivity"</span></span><span class="o">,</span> <span class="s"><span class="string" style="color: rgb(221, 17, 68);">"Activity result fragment index out of range: 0x"</span></span> <span class="o">+</span> <span class="n">Integer</span><span class="o">.</span><span class="na">toHexString</span><span class="o">(</span><span class="n">requestCode</span><span class="o">));</span> <span class="k"><span class="keyword" style="font-weight: bold;">return</span></span><span class="o">;</span> <span class="o">}</span> <span class="n">Fragment</span> <span class="n">frag</span> <span class="o">=</span> <span class="o">(</span><span class="n">Fragment</span><span class="o">)</span><span class="k"><span class="keyword" style="font-weight: bold;">this</span></span><span class="o">.</span><span class="na">mFragments</span><span class="o">.</span><span class="na">mActive</span><span class="o">.</span><span class="na"><span class="keyword" style="font-weight: bold;">get</span></span><span class="o">(</span><span class="n">index</span><span class="o">);</span> <span class="k"><span class="keyword" style="font-weight: bold;">if</span></span> <span class="o">(</span><span class="n">frag</span> <span class="o">==</span> <span class="kc"><span class="keyword" style="font-weight: bold;">null</span></span><span class="o">)</span> <span class="o">{</span> <span class="n">Log</span><span class="o">.</span><span class="na">w</span><span class="o">(</span><span class="s"><span class="string" style="color: rgb(221, 17, 68);">"FragmentActivity"</span></span><span class="o">,</span> <span class="s"><span class="string" style="color: rgb(221, 17, 68);">"Activity result no fragment exists for index: 0x"</span></span> <span class="o">+</span> <span class="n">Integer</span><span class="o">.</span><span class="na">toHexString</span><span class="o">(</span><span class="n">requestCode</span><span class="o">));</span> <span class="o">}</span> <span class="k"><span class="keyword" style="font-weight: bold;">else</span></span> <span class="o">{</span> <span class="n">frag</span><span class="o">.</span><span class="na">onActivityResult</span><span class="o">(</span><span class="n">requestCode</span> <span class="o">&</span> <span class="mi"><span class="number" style="color: rgb(0, 153, 153);">0</span></span><span class="number" style="color: rgb(0, 153, 153);">xFFFF</span><span class="n"></span><span class="o">,</span> <span class="n">resultCode</span><span class="o">,</span> <span class="n">data</span><span class="o">);</span> <span class="o">}</span> <span class="k"><span class="keyword" style="font-weight: bold;">return</span></span><span class="o">;</span> <span class="o">}</span> <span class="kd">super</span><span class="o">.</span><span class="na">onActivityResult</span><span class="o">(</span><span class="n">requestCode</span><span class="o">,</span> <span class="n">resultCode</span><span class="o">,</span> <span class="n">data</span><span class="o">);</span> <span class="o">}</span>
很显然,设计者把Fragment的下标+1左移16位来标记这个request是不是Fragment的,拿到result再解码出下标,直接取对应的Fragment,这样并没有去考虑对Fragment嵌套Fragment做一个Map映射,所以出现了这种BUG。
但是如果我们需要在OnActivityResult的时候处理一些事情的话,我们可以通过在子Fragment中以getParentFragment.startActivityForResult的方式来启动,然后在父Fragment中去接收数据,我们需要在子Fragment中提供一个方法,如:getResultData(Object obj),通过父Fragment中的子Fragment实例去调用这个方法,把相应的数据传过去,然后去更新子Fragment。
或者在子fragment实现一个接口,让你启动的activity去调用他。