@@ -80,6 +80,12 @@ public class AccountFormFragment extends SherlockFragment {
8080 * Accounts database adapter
8181 */
8282 private AccountsDbAdapter mAccountsDbAdapter ;
83+
84+ /**
85+ * Whether the AccountsDbAdapter is created inside this class.
86+ * If so, it should be also closed by this class
87+ */
88+ private boolean mReleaseDbAdapter = false ;
8389
8490 /**
8591 * List of all currency codes (ISO 4217) supported by the app
@@ -191,6 +197,7 @@ public AccountFormFragment() {
191197 static public AccountFormFragment newInstance (AccountsDbAdapter dbAdapter ){
192198 AccountFormFragment f = new AccountFormFragment ();
193199 f .mAccountsDbAdapter = dbAdapter ;
200+ f .mReleaseDbAdapter = false ;
194201 return f ;
195202 }
196203
@@ -199,6 +206,7 @@ public void onCreate(Bundle savedInstanceState) {
199206 super .onCreate (savedInstanceState );
200207 setHasOptionsMenu (true );
201208 if (mAccountsDbAdapter == null ){
209+ mReleaseDbAdapter = true ;
202210 mAccountsDbAdapter = new AccountsDbAdapter (getSherlockActivity ());
203211 }
204212
@@ -660,8 +668,14 @@ public void onDestroy() {
660668 super .onDestroyView ();
661669 if (mParentAccountCursor != null )
662670 mParentAccountCursor .close ();
663- //do not close the database adapter. We got it from the activity,
664- //the activity will take care of it.
671+ // The mAccountsDbAdapter should only be closed when it is not passed in
672+ // by other Activities.
673+ if (mReleaseDbAdapter == true && mAccountsDbAdapter != null ) {
674+ mAccountsDbAdapter .close ();
675+ }
676+ if (mDefaultTransferAccountCursorAdapter != null ) {
677+ mDefaultTransferAccountCursorAdapter .getCursor ().close ();
678+ }
665679 }
666680
667681 private void saveAccount () {
0 commit comments