I am creating a SQLiteDatabase in inside a Service and I am trying to pass the record id to another Activity so that I can populate a ListView. I guess I could pass the dataset to a method inside the receiving Activity and use that to populate the ListView. Is that a good plan of action? Is there a better way?
Asked
Active
Viewed 70 times
0
-
you can use intents extra method for passing data to another activity and list them. checkout http://stackoverflow.com/questions/2405120/how-to-start-an-intent-by-passing-some-parameters-to-it – erdimeola Jul 14 '13 at 00:23
-
Using an intent just to pass the id for a reference is an OK idea as I see it since its small data, no sense creating complex object for small data. – kabuto178 Jul 14 '13 at 00:24
-
As mentioned above you could use intent and use broadcast to send your intent. then your activity should register to listen to that intent. Also you could use bound service and bind your activity to your service and then get the data there. – Saeid Farivar Jul 14 '13 at 00:57
2 Answers
0
Using Service
s for database manipulation is very bad idea.
There are two recommended approaches for correctly managing SQLite Databases.
- Use an Abstract Factory to Instantiate the SQLiteOpenHelper
- Wrap the SQLiteDatabase in a ContentProvider (which is best method i will suggest to you)
References
- http://developer.android.com/training/basics/data-storage/databases.html
- correctly-managing-your-sqlite-database.html
I hope that this will help you to get the idea.

Shajeel Afzal
- 5,913
- 6
- 43
- 70
0
If you simply want the record Id into another activity, then you can use:
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
i.putExtra("ID", "1"); // where id value is 1
startActivity(i) ;
In Second Activity:
String id = getIntent().getExtras().getString("ID");

Husnain Iqbal
- 466
- 6
- 16