Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass database objects between activities (Android)

Tags:

android

Is there any way to pass database object between activities. I have already tried the following ways for doing this.

  1. Implementing interface.
  2. Using functions.
like image 904
Haisum Abbas Avatar asked Jul 22 '26 18:07

Haisum Abbas


1 Answers

I guess you are looking for a Singleton. Maybe this will help you:

  • Android multiple activities access one java class

If you are using a SQLiteOpenHelper I HIGHLY recommend you to read this:

  • Correctly Managing Your SQLite Database

I think you should be fine with Approach #1 which uses a singleton with the abstract factory pattern. Read the article its very informative. More on the topic and Pros n cons are here

like image 192
Langusten Gustel Avatar answered Jul 25 '26 09:07

Langusten Gustel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!